Guest User

Untitled

a guest
Nov 21st, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. inputs = [
  2. itertools.count(),
  3. [2, 4, 6],
  4. [100, 101, 1000],
  5. []]
  6.  
  7. def multisort(inputs):
  8. outs = [[None, input] for input in inputs]
  9. while True:
  10. for out in outs:
  11. if out[0] is None: out[0] = out[1].next()
  12. outs = sorted(outs) # prob need to sort by 1st elt specifically
  13. yield outs[0][0]
  14. outs[0][0] = None
  15. ...
  16.  
  17.  
  18.  
  19. while True:
  20. # make sure we have the next value from each iterator
  21. for i in xrange(0, len(inputs):
  22. if last[i] is None:
  23. last[i] = inputs[i].next()
  24.  
  25. # find the smallest value in last
  26. # yield it and replace it with None
  27. small_index = None
  28. small_value = None
  29. for i in xrange(0, len(inputs)):
  30. if small_index is None or last[i] < small_value:
  31. small_index = i
  32. small_value = last[i]
  33. yield last[i]
  34. last[i] = None
  35.  
  36. for i in multisort(inputs):
  37. print i
  38.  
  39. # prints 0 1 2 3 4 5 6 100 101 1000
Add Comment
Please, Sign In to add comment