[Tutor] While until the end of a list

Peter Otten __peter__ at web.de
Tue Mar 14 09:09:15 EDT 2017


Toni Fuente via Tutor wrote:

>     strings_chunk = list(itertools.chain.from_iterable(chunk))
>     for item in strings_chunk:
         ...

Note that if you are iterating over strings_chunk just once there is no need 
to create an in-memory list.

for item in itertools.chain.from_iterable(chunk):
   ...

will work, too, without the consumption of time and memory needed to build 
the list.



More information about the Tutor mailing list