+ 1

Hello. Can someone explain it to me?

I see a python-challenge: List comprehension can be used to ... ? Tge right answer is ' construct a list'.

24th May 2019, 12:21 PM
Vincent Joe Parker
Vincent Joe Parker - avatar
4 Respostas
+ 5
You can fill a list with items, for example: list_ = [] for i in range(10): list_.append(int(input()) This creates a list and after that fills it with ten numbers the user inputs. Now a list comprehension is a shortcut: list_ = [int(input()) for i in range(10)]
24th May 2019, 12:30 PM
HonFu
HonFu - avatar
+ 2
I don't know how the term was intended originally. I understand it like: 'A comprehensive way to build a list' (like an all-in-one package, you don't have to do each step separately). You can use it for other container types as well: # assuming you have two containers keys and values {key: value for key in keys for value in values} tuple(n * 2 for n in range(100)) etc.
24th May 2019, 1:16 PM
HonFu
HonFu - avatar
+ 1
What does it mean this term?: List comprehension?
24th May 2019, 12:48 PM
Vincent Joe Parker
Vincent Joe Parker - avatar
+ 1
I have understood . It is a generator. Thank you.
24th May 2019, 12:55 PM
Vincent Joe Parker
Vincent Joe Parker - avatar