0
Why isn't it working properly?
a = [] b = input().split(" ") p = [] for i in b: a.append(int(i)) e = input().split(" ") for w in e: p.append(int(w)) (a+p).sort() print(a+p)
5 Answers
+ 1
1. Because you sorted two lists together. But didn't save result in any variable.
2. The code will give error if to enter space more than once at once.
3.code will give error if to enter anything but digit.
+ 1
Shahir,
(a+p).sort()
here a + p creates transient array with all elements of array a and array p. And call to sort() on this transient array is get sorted. It doesn't affect array a, p.
So, sort() call works properly. Result of sort() call is not available.
DHANANJAY PATEL
0
Task is to sort the integers of two arrays
Example
Input:
[1,3,7]
[0,2,4]
Output:
0,1,2,3,4,7
0
list.sort() sorts the list in place
https://python-reference.readthedocs.io/en/latest/docs/list/sort.html
you need to store your list inside the variable and then use sort() on it.
https://code.sololearn.com/c2LK0e135a9M/?ref=app
0
Shahir The new sorted list (a+p) is garbage collected as there's no reference to it saved in the code. Try using the sorted() function instead.