0
What is a list comprehensions in python 3?
4 Respuestas
+ 1
+ 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)]
0
i saw this but I don't understand am a bigginer