Realising an Iterator

Learn why you would need to realize an iterator and how you would go about doing it.

It is sometimes useful to convert an iterator into a concrete sequence such as a list. This is sometimes called “realizing” the iterator.

Reasons for realizing an iterator

There are several reasons you might want to realize an iterator:

  • To find its length
  • To access the elements more than once (an iterator can only be read from once, afterwards it is spent)
  • To access the elements in a different order
  • To print it

Get hands-on with 1400+ tech skills courses.