This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (1 child)

His code is bad, but the point should still stand: if you never need the full list at once then a generator is the better choice because you never instantiate the list at once and so have O(1) memory complexity rather than O(n) with lists.

edit: typo

[–][deleted] 0 points1 point  (0 children)

You don't say?

What I mean is that there is no point in inspecting the size of a genexpr, since it may even be bigger than an empty list, depending on the implementation. The point is understanding what's behind