Many methods in Python take an iterable as their argument (this is usually noted in the signature description in the documentation). A generator expression is, much like a list, iterable. Therefore it is not necessary to actually construct a list (neither explicitly or via list comprehension), in fact it simply uses up more memory.
Yes, it does work without square brackets. I just checked, because I got identical solution except of square brackets I got list(). After removing list() it still works.
That is very cool solution. I wish I guessed it
Many methods in Python take an iterable as their argument (this is usually noted in the signature description in the documentation). A generator expression is, much like a list, iterable. Therefore it is not necessary to actually construct a list (neither explicitly or via list comprehension), in fact it simply uses up more memory.
Yes, it does work without square brackets. I just checked, because I got identical solution except of square brackets I got
list()
. After removinglist()
it still works.Nice - one of those solutions that makes you say, "Of course! Why didn't I think of that?"
This comment is hidden because it contains spoiler information about the solution