f | def joinseq(*sequences): | f | def joinseq(*sequences): |
| iterators = [iter(seq) for seq in sequences] | | iterators = [iter(seq) for seq in sequences] |
| iterators_count = len(iterators) | | iterators_count = len(iterators) |
| iterator_array = [None] * iterators_count | | iterator_array = [None] * iterators_count |
n | for i, iterator in enumerate(iterators): | n | for i, it in enumerate(iterators): |
| element = next(iterator, None) | | el = next(it, None) |
| if element is not None: | | if el is not None: |
| iterator_array[i] = element | | iterator_array[i] = el |
| else: | | else: |
| iterator_array[i] = None | | iterator_array[i] = None |
| iterators_count -= 1 | | iterators_count -= 1 |
| while iterators_count > 0: | | while iterators_count > 0: |
| min_index = None | | min_index = None |
| min_value = None | | min_value = None |
n | for i, el in enumerate(iterator_array): | n | for i, val in enumerate(iterator_array): |
| if el is None: | | if val is None: |
| continue | | continue |
n | if min_value is None or el < min_value: | n | if min_value is None or val < min_value: |
| min_value = el | | min_value = val |
| min_index = i | | min_index = i |
| if min_index is not None: | | if min_index is not None: |
| yield min_value | | yield min_value |
t | element = next(iterators[min_index], None) | t | el = next(iterators[min_index], None) |
| if element is not None: | | if el is not None: |
| iterator_array[min_index] = element | | iterator_array[min_index] = el |
| else: | | else: |
| iterator_array[min_index] = None | | iterator_array[min_index] = None |
| iterators_count -= 1 | | iterators_count -= 1 |