+ 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...