Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- lists = [[1,2,3],
- [-100, 70],
- [23, 50]]
- pivot = [0] * len(lists) # [0, 0, 0]
- finalSorted = []
- for _ in range(sum(len(x) for x in lists)): # quantity of items in 2D array
- smallest = sys.maxint
- index_of_smallest = -1
- for indx, list in enumerate(lists):
- if pivot[indx] < len(list):
- current = list[pivot[indx]]
- else:
- continue
- if current < smallest:
- smallest = current
- index_of_smallest = indx
- finalSorted.append(smallest)
- pivot[index_of_smallest] = pivot[index_of_smallest]+1
- print(finalSorted) #[-100, 1, 2, 3, 23, 50, 70]
Add Comment
Please, Sign In to add comment