Search code examples
pythoniteratorlist-comprehension

How can I create a list of elements from an iterator (convert the iterator to a list)?


Given an iterator user_iterator, how can I iterate over the iterator a list of the yielded objects?

I have this code, which seems to work:

user_list = [user for user in user_iterator]

But is there something faster, better or more correct?


Solution

  • list(your_iterator)