f | from itertools import compress | f | from itertools import compress |
| | | |
| def joinseq(*seq): | | def joinseq(*seq): |
t | seq = [iter(s) for s in seq] | t | seq_it = [iter(s) for s in seq] |
| tmp = [next(it) for it in seq] | | letters = [next(it) for it in seq_it] |
| t = list(compress(tmp, [el != -1 for el in tmp])) | | tmp = list(compress(letters, [el != -1 for el in letters])) |
| while len(t): | | while len(tmp): |
| m = min(t) | | min_val = min(tmp) |
| yield m | | yield min_val |
| idx = tmp.index(m) | | idx = letters.index(min_val) |
| tmp[idx] = next(seq[idx], -1) | | letters[idx] = next(seq_it[idx], -1) |
| t = list(compress(tmp, [el != -1 for el in tmp])) | | tmp = list(compress(letters, [el != -1 for el in letters])) |