I have the following problem. I have to implement a function as a generator, which expects any number of iterables. It can be assumed that the iterables issue their elements each time in the same order. The function should return all elements that are in the same place in all iterables (view asserts):
def intersect(*iterables, **kwiterables):
for obj in iterables:
#need help here :)
#already tried something like:
# obj = (var for var in obj if var in iterables)
yield obj
#asserts:
assert list(intersect((1,2,3))) == [1,2,3]
assert list(intersect((1,2,3), (1,"x",3))) == [1,3]
assert list(intersect([1,1,1,1,1,1,1,1,1], [1,2,1,2,1,2,1,2,1,2], k = [3,3,1,3,3,1,3,3,1,3,3,1])) == [1,1]
Would be glad about a solution of my problem with explanation.