+ 2
Can anyone help me? In a random list how to put all even numbers in the front?
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
+ 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])
+ 2
Jan Markus Thanks
0
front? you mean the beginning of the list?