On 2016-05-10 23:36, DFS wrote:
[snip]

If lists are still being created:

* at every moment in time, len(list1) returns a length that doesn't
change even if data is added to the list after the call to len().

Example: If the list has 100 items in it at the point len(list) is called:

for i in range(len(list1))

will never iterate more than 100x, no matter how large list1 grows to.

Caveat: since list1 may be bigger or smaller than the other lists at
that moment in time, an error may occur when using list2[i], list3[i].


Is that all correct as you understand it?

Yes.


* at every moment in time, zip(list1, list2, etc) will return a fixed,
same-length lists of tuples, which doesn't change even if data is added
to any of the lists after the call to zip().

Example: if the lists have 100, 97 and 102 items in them at the point
zip(lists) is called:

for item1, item2, item3 in zip(list1, list2, list3)

will never iterate beyond 97x, even if the lists grow while the
enumeration is occurring.

Caveat: since zip() possibly truncates lists, the results - the usage of
the data - could be completely invalid.


Is that all correct as you understand it?

In Python 2, zip iterates through the arguments immediately and returns a list of tuples, so the answer is yes.

In Python 3, zip returns a lazy iterator (like itertools.izip in Python 2) that gets the values from the arguments _on demand_, so the answer is no.

[snip]

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to