+ 1
What does this list comprehension do?
4 Answers
+ 1
>>> S = [x**2 for x in range(10)]
>>> V = [2**i for i in range(13)]
>>> M = [x for x in S if x % 2 == 0]
>>>Â
>>> print S; print V; print M
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096]
[0, 4, 16, 36, 64]
0
They put values in a list.
example:
>>> food = [ x for x in ["apple",orange","ananas"]]
example 2:
>>> square = [x**2 for x in range(1,11)]
[1,4,9,16,25,36,49,64,81,100]
0
thanks for helping....
0
thank you soo much...