I have a generator function, i've filled in the function if there are no more_seqs. But I feel trouble if there are more sequences. I need to generate 1 tuple at a time. if the function call is

generate_zip(range(5),range(3),range(4),range(5)) then the tuple generated should be (0,0,0,0) (1,1,1,1) n so on

def generator_zip(seq1, seq2, *more_seqs):
    t1 = [(x,y) for i,x in enumerate(seq1) for j,y in enumerate(seq2) if i == j]
    if len(more_seqs) == 0:
        for tup in t1:
            yield tup

can anyone suggest me a way to unpack more_seqs and then join the tuples of seq1,seq2 with more_seqs tuples and then yield??

Your function does what zip builtin function does. Just much more inefficiently.

It takes iterables, and return a list of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.
The returned list is truncated in length to the length of the shortest argument sequence.

I suggest just to use zip, or itertools.izip
t1=zip(seq1,seq2,*more_seqs)

See: http://docs.python.org/2/library/itertools.html?highlight=itertools#itertools.izip

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.