0
In one-dimensional list a=[a1, a2, ..., an] all positive elements that have an even sequence number, rewrite the beginning of...
In one-dimensional list a=[a1, a2, ..., an] all positive elements that have an even sequence number, rewrite the beginning of the list. in Python
4 odpowiedzi
+ 1
move the items with even to the beginning? you could use a nested loop first to iterate items and second to check the second number of the element if even move to empty variable list index 0 else append
+ 1
import random
a = [random.randint(-9,9) for i in range(20)]
print(a)
print([i for i in a if not(i%2) and i>=0]+[i for i in a if not(not(i%2) and i>=0)])
0
repost?
0
thank you very much