Guest User

Untitled

a guest
Nov 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import sys
  2.  
  3. lists = [[1,2,3],
  4. [-100, 70],
  5. [23, 50]]
  6. pivot = [0] * len(lists) # [0, 0, 0]
  7. finalSorted = []
  8.  
  9.  
  10. for _ in range(sum(len(x) for x in lists)): # quantity of items in 2D array
  11. smallest = sys.maxint
  12. index_of_smallest = -1
  13. for indx, list in enumerate(lists):
  14. if pivot[indx] < len(list):
  15. current = list[pivot[indx]]
  16. else:
  17. continue
  18. if current < smallest:
  19. smallest = current
  20. index_of_smallest = indx
  21.  
  22. finalSorted.append(smallest)
  23. pivot[index_of_smallest] = pivot[index_of_smallest]+1
  24.  
  25. print(finalSorted) #[-100, 1, 2, 3, 23, 50, 70]
Add Comment
Please, Sign In to add comment