[Tutor] Nested list comprehensions

Alan Gauld alan.gauld at yahoo.co.uk
Sun Oct 18 07:27:12 EDT 2020


On 18/10/2020 08:47, Manprit Singh wrote:

> I have already tested the code.....the answer is correct too.

Which is the reason for Mark's frustration. Your understanding of
how to write a nested comprehension must be correct if the code
works and produces the right answer. The interpreter is the
definitive arbiter of what is right. So it is not clear what
exactly you are asking for.

> My concern was just to check if my understanding about using nested list
> comprehensions is correct or not.

Correct in what way? Technically yes, it is obviously right
if the interpreter can execute it and produce the result you
are looking for. What more do you want to know? Please ask
specific questions then we can provide specific answers.

If you want to know about whether its an appropriate scenario
for a nested comprehension then say so - the answer is probably.
We'd need more context to be definitive. The only thing to be
wary of with nested comprehensions is that they can rapidly
become unreadably complex and they are very difficult to
debug because too much is happening in a single line.

Beyond that, what do you want to know?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list