f | def joinseq(*seqs): | f | def joinseq(*seqs): |
| seqs = [iter(seq) for seq in seqs] | | seqs = [iter(seq) for seq in seqs] |
n | s = set() | n | elems = set() |
| for (i, seq) in enumerate(seqs): | | for (i, seq) in enumerate(seqs): |
t | val = next(seq, None) | t | elem = next(seq, None) |
| if val is not None: | | if elem is not None: |
| s.add((val, i)) | | elems.add((elem, i)) |
| while s: | | while elems: |
| (val, i) = min(s) | | (m, idx) = min(elems) |
| s.discard((val, i)) | | elems.discard((m, idx)) |
| yield val | | yield m |
| new_val = next(seqs[i], None) | | elem = next(seqs[idx], None) |
| if new_val is not None: | | if elem is not None: |
| s.add((new_val, i)) | | elems.add((elem, idx)) |