+ 2

Can anyone help me? In a random list how to put all even numbers in the front?

5th Apr 2018, 3:43 PM
Пиров Мустафо
Пиров Мустафо - avatar
4 Respostas
+ 2
Jan, i dont think that's what he meant. i think he wanted the transform to be within the same list. if so you should use this function: def SortEven(arr): z=0 for x in range(len(arr)): if(arr[x]%2==0): tmp=arr[z] arr[z]=arr[x] arr[x]=tmp z+=1 return arr
5th Apr 2018, 4:11 PM
Tomer Sim
Tomer Sim - avatar
+ 2
import random a = [random.randint(0,9) for i in range(20)] print(a) print([i for i in a if not(i%2)]+[i for i in a if i%2])
5th Apr 2018, 6:38 PM
Louis
Louis - avatar
+ 2
Jan Markus Thanks
6th Apr 2018, 12:42 PM
Louis
Louis - avatar
0
front? you mean the beginning of the list?
5th Apr 2018, 4:06 PM
Tomer Sim
Tomer Sim - avatar