Write a generator/iterator expression for this sequence

Looks like you’re really struggling with this despite an apparent good faith effort.

So here is the answer:

from typing import Iterator
X = [1,2,3]
Y = [5,6,7]
S : Iterator[tuple[int, int]] = ((a,b**2) for a,b in zip(X,Y))
assert set(S)=={(1,25), (2,36), (3,49)}

zip forms pairs like [(1, 5), (2, 6), (3, 7)], so you can iterate on them using a loop or list comprehension.

Leave a Comment