Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inputs = [
- itertools.count(),
- [2, 4, 6],
- [100, 101, 1000],
- []]
- def multisort(inputs):
- outs = [[None, input] for input in inputs]
- while True:
- for out in outs:
- if out[0] is None: out[0] = out[1].next()
- outs = sorted(outs) # prob need to sort by 1st elt specifically
- yield outs[0][0]
- outs[0][0] = None
- ...
- while True:
- # make sure we have the next value from each iterator
- for i in xrange(0, len(inputs):
- if last[i] is None:
- last[i] = inputs[i].next()
- # find the smallest value in last
- # yield it and replace it with None
- small_index = None
- small_value = None
- for i in xrange(0, len(inputs)):
- if small_index is None or last[i] < small_value:
- small_index = i
- small_value = last[i]
- yield last[i]
- last[i] = None
- for i in multisort(inputs):
- print i
- # prints 0 1 2 3 4 5 6 100 101 1000
Add Comment
Please, Sign In to add comment