ex. if input "-1 1 3 -2 2", answer should be "-1 -2 1 3 2"
def specialsort(numbers):
list1 = []
list2 = []
list = numbers.split(" ")
for number in list:
if int(number)<0:
list1.append(number)
else:
list2.append(number)
result = list1 + list2
return " ".join(result)
My question is : In this source code above, when I first used extend
list function like result = list1.extend(list2)
, it turned out to be an error saying TypeError: can only join an iterable
. And when I edited it into "result = list1 + list2", it finally worked well. But I still don't understand why the one with extend function doesn't work while the other works well without problem because list1.extend(list2)
returns same result with 'list1 + list2'.
If anyone knows about this problem, can you please explain about it? I would really appreciate your answer. Thanks :)