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

6th Apr 2018, 4:13 PM
Пиров Мустафо
Пиров Мустафо - avatar
4 Respostas
+ 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
6th Apr 2018, 6:09 PM
Markus Kaleton
Markus Kaleton - avatar
+ 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)])
6th Apr 2018, 9:28 PM
Louis
Louis - avatar
0
repost?
6th Apr 2018, 6:06 PM
Markus Kaleton
Markus Kaleton - avatar
0
thank you very much
8th Apr 2018, 9:38 PM
Пиров Мустафо
Пиров Мустафо - avatar