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