Python Forum
question about list comprehension
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
question about list comprehension
#1
I am practicing for the python PCAP exam and i don't understand this excercise:

How many empty lines will the following snippet send to the console?
l = [[c for c in range(r)] for r in range(3)]
for x in l:
    if len(x) < 2:
    print()
I do understand easy list comprehensions but not this one with c for c in range®.

If someone could explain this I would be very thankful.
Reply
#2
it is list comprehension inside list comprehension. the result will be list of lists
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

Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020