+ 1

What does this list comprehension do?

13th Sep 2016, 3:04 AM
Gurtej Singh
Gurtej Singh - avatar
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]
13th Sep 2016, 3:19 AM
ÖzgĂŒr Bildik
ÖzgĂŒr Bildik - avatar
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]
13th Sep 2016, 4:59 AM
Giovanni Gatto
Giovanni Gatto - avatar
0
thanks for helping....
25th Sep 2016, 6:21 PM
Gurtej Singh
Gurtej Singh - avatar
0
thank you soo much...
5th Oct 2016, 10:46 AM
Gurtej Singh
Gurtej Singh - avatar