Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
arrays = [ [1,7], [2,3,4], [10,11,12,13] ]
while arrays:
for (index, item) in enumerate(arrays):
if len(arrays[index]) == 0:
arrays.pop(index)
continue
print arrays[index].pop(0)
print arrays
@managedkaos

This comment has been minimized.

Copy link
Owner Author

@managedkaos managedkaos commented Aug 1, 2017

1
2
10
7
3
11
12
4
13

Visualizing the array shrinkage:

1
[[7], [2, 3, 4], [10, 11, 12, 13]]
2
[[7], [3, 4], [10, 11, 12, 13]]
10
[[7], [3, 4], [11, 12, 13]]
7
[[], [3, 4], [11, 12, 13]]
3
[[], [4], [11, 12, 13]]
11
[[], [4], [12, 13]]
12
[[4], [13]]
4
[[], [13]]
13
[[], []]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment