Jan-07-2019, 12:27 PM
Can you please explain me Python List Comprehension.
Python List Comprehension.
|
||
Jan-07-2019, 12:27 PM
Can you please explain me Python List Comprehension.
Jan-07-2019, 12:35 PM
Did you check our tutorial on comprehension expressions? Or any other available online? It will be easier to help if you are more specific which part you don't understand.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link Create MCV example Debug small programs
The list comprehension is a way to declare a list in one line of code. Let’s take a look at one such example.
>>> [i for i in range(1,11,2)] [1, 3, 5, 7, 9] >>> [i*2 for i in range(1,11,2)] [2, 6, 10, 14, 18]
Jan-08-2019, 12:30 PM
As almost everything else in Python it's very close to natural language. This Python code:
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. | ||
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
List comprehension: | paul18fr | 1 | 1,914 |
Oct-29-2021, 05:36 PM Last Post: Yoriz |
|
list comprehension invalid syntax | mcgrim | 1 | 6,028 |
Jun-12-2019, 08:28 PM Last Post: Yoriz |
|
Help me understand a simple list comprehension | PiPy | 6 | 5,177 |
Oct-17-2018, 07:59 PM Last Post: PiPy |