Answers for "py iterate for each line"

9

python for loop one line

>>> x = [1, 2, 3, 4, 5]
>>> y = [2*a for a in x if a % 2 == 1]
>>> print(y)
[2, 6, 10]
Posted by: Guest on July-10-2020
0

python list iterate in 1 line

mylist = [1,4,5,8,9,11,13,12]

newlist = [x for x in mylist if x%2 == 1]
print(newlist)
Posted by: Guest on October-30-2021

Python Answers by Framework

Browse Popular Code Answers by Language