list1[start:stop] creates a new list, period. This is always the case, regardless of whether you directly execute the result or execute the function between them or use it in any other context (you will need a moderately static language or a complex type of output for optimization even for simple instances of the first case).
Note that this does not depend on iteration ! The iteration itself is not copied, and the list cuts the copies, even if you throw away the result.
It only copies pointers, so if you always accept very small sublists, you probably won't notice any difference. If there are more sublists, you can either itertools.islice over the indexes ( [x]range ) or use itertools.islice . The latter must first skip the start points, so you can pay a hefty temporary penalty for saving memory. The first is ugly, but most effectively asymptomatic.
source share