0

What is a list comprehensions in python 3?

20th Jul 2018, 6:21 AM
farhad gohar
farhad gohar - avatar
4 Answers
20th Jul 2018, 8:13 AM
KrOW
KrOW - avatar
+ 1
simply put it is a way to make a list without having to input every item of the list. you could define a list of even numbers like this: evens = [0,2,4,6,8] or you could use list comprehensions: evens = [2*i for i in range(5)] The second way comes in handy when lists are bigger or when for example the size of the list depends on input: n = int(input()) evens = [2*i for i in range(n)]
20th Jul 2018, 8:40 AM
davy hermans
davy hermans - avatar
0
i saw this but I don't understand am a bigginer
20th Jul 2018, 8:03 AM
farhad gohar
farhad gohar - avatar