Олег Алексеевич Бугай, ФКИ, группа 108м SeqJoin 9920 | Chiganov Aleksey Andreevich M108 Facultet of Space Research MSU SeqJoin 9403 | ||||
---|---|---|---|---|---|
f | 1 | def joinseq(*seq): | f | 1 | def joinseq(*seq): |
n | 2 | it = [iter(s) for s in seq] | n | 2 | iterators = [iter(seq_) for seq_ in seq] |
3 | v = [next(k) for k in it] | 3 | val = [next(i) for i in iterators] | ||
4 | while True: | 4 | while True: | ||
t | 5 | m_it = min(v) | t | 5 | min_item = min(val) |
6 | yield m_it | 6 | yield min_item | ||
7 | i = v.index(m_it) | 7 | idx = val.index(min_item) | ||
8 | v[i] = next(it[i], None) | 8 | val[idx] = next(iterators[idx], None) | ||
9 | if v[i] == None: | 9 | if val[idx] == None: | ||
10 | v.pop(i) | 10 | val.pop(idx) | ||
11 | it.pop(i) | 11 | iterators.pop(idx) | ||
12 | if v == []: | 12 | if val == []: | ||
13 | break | 13 | break |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|