python for loop in one line

43

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

newlist = [x for x in mylist if x%2 == 1]
print(newlist)
[thing for thing in list_of_things] 
>>> x = [1, 2, 3, 4, 5]
>>> y = [2*a for a in x if a % 2 == 1]
>>> print(y)
[2, 6, 10]
>>> [(i) for i in my_list if i=="two"]
['two']
print(stripped_line)

Comments

Submit
0 Comments