[Tutor] Nested list comprehensions

Alan Gauld alan.gauld at yahoo.co.uk
Sun Oct 18 15:02:42 EDT 2020


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

> def two_d(row, col, ele):
>     return [[ele for _ in range(col)] for _ in range(row)]
> 
> 
> x = two_d(3, 5, 8)
> print(x)
> 
> and got the same answer . See here the nested comprehension is quite clear
> to read, 

I suspect that's only because it was you who wrote it. Personally
I find it about the same as the example from the tutorial. They
are almost identical in form.


-- 
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