0
Python program to print new list by sorted number in given list is like [1st largest,1st smallest, 2nd largest, 2nd smallest]
Example Input: [3,7,8,2,5,1] Output: [8,1,7,2,5,3]
4 Respostas
+ 1
tmp_list=input_list.sort()
output=[]
for i in range(len(tmp_list)):
j=len(tmp_list)-i-1
if (j>i):
output.append(tmp_list[j])
output.append(tmp_list[i])
elif (j=i):
output.append(tmp_list[i])
else:
pass
print(output)
I hope this help. It’s not probably the best solution but it should work.
+ 1
What if the list has odd number of items? what should be done with the orphaned item?
0
Show us your attempt and we will help you!
0
I think that it could be added at the end-> as the 4 in the ex below.
Ex.
Input= [1,2,3,4,5,6,7]
Output=[7,1,6,2,5,3,4]