OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Understanding list comprehension when "exploding" list of lists [duplicate]

  • Thread starter Thread starter Caterina
  • Start date Start date
C

Caterina

Guest
I came across this code:

Code:
[item for sublist in non_empty_lists for item in sublist]

But I don't really understand what it does. non_empty_lists is a list of lists. I understand it basically "flattens" the list. But I don't really get the syntax. Could you please give me a hint of the algorithm behind this list comprehension?
<p>I came across this code:</p>
<pre><code>[item for sublist in non_empty_lists for item in sublist]
</code></pre>
<p>But I don't really understand what it does. <code>non_empty_lists</code> is a list of lists.
I understand it basically "flattens" the list. But I don't really get the syntax. Could you please give me a hint of the algorithm behind this list comprehension?</p>
 

Latest posts

S
Replies
0
Views
1
Souvik Manna
S
S
Replies
0
Views
1
Shelling ford
S
Top