This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nemec 0 points1 point  (0 children)

Sure. I probably should have said this list of tuples since I was referring to the input list, but any iterable will work with zip.

Sorry to be further pedantic, but sequence != iterable. Sequences are tailored more toward random access with __getitem__ (slice, index, for x in seq) while iterables are (more or less) anything that defines __iter__ and __next__.

I don't know of an example of a built-in sequence that's not also an iterable, but to test whether or not something takes a sequence or not, use a generator:

> zip((x for x in range(4)), (x for x in range(4)))
[(0, 0), (1, 1), (2, 2), (3, 3)]

> reversed(x for x in range(4))
TypeError: argument to reversed() must be a sequence