1

I have two iterators (A_subseq and B_subseq), and each iterator has two yield outputs (Aseq and Ahseq from A_subseq). I need to keep index count of both iterators. This can be done if I can combine the two for loops into a single loop.

Both a and b are iterators. k is just a constant integer.

a_count = 0
b_count = 0

A_subseq = subsequenceHashes(a,k)
B_subseq = subsequenceHashes(b,k)

Match = Multidict()

for Aseq,Ahash in A_subseq:
    Match.put(Ahash,Aseq)

for Bseq,Bhash in B_subseq:
    b_count += 1
    if Bseq in Match.get(Bhash):
        yield xxx

Does anyone know if I can combine these two for loops so that I can keep count of both a_count and b_count?

Night0
  • 347
  • 5
  • 13

1 Answers1

5

I believe this is what you are after:

for (a, b), (c, d) in izip(iter1, iter2)

This is one of properties of Python's beauty

Israel Unterman
  • 13,158
  • 4
  • 28
  • 35