Skip to content

Instantly share code, notes, and snippets.

@managedkaos
Created August 1, 2017 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save managedkaos/bcc1366c4ac31ca3d1e020ad35b8f32b to your computer and use it in GitHub Desktop.
Save managedkaos/bcc1366c4ac31ca3d1e020ad35b8f32b to your computer and use it in GitHub Desktop.
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
Copy link
Author

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