views:

137

answers:

1

Having an iterator object, is there something faster, better or more correct than a list comprehension to get a list of the objects returned by the iterator?

user_list = [user for user in user_iterator]
+18  A: 
list(your_iterator)
mikerobi
Actually, almost always quite a bit faster. Also, much more obvious.
Thomas Wouters
+1 after my edit. ;)
FogleBird
@systempuntoout It runs entirely in C. The list comprehension is in python. Of course it runs faster.
aaronasterling
Removed my "probably faster" description
mikerobi
+1 "Sibyl Fawlty" badge
John Machin
@systempuntoout, done
mikerobi