Last active
September 1, 2016 22:04
-
-
Save craigderington/826c08274996fe2a49e9 to your computer and use it in GitHub Desktop.
Breaks a list into 'n' pieces horizontally.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def partition_horizontal(thelist, n): | |
""" | |
break a list into 'n' pieces horizontally | |
""" | |
try: | |
n = int(n) | |
thelist = list(thelist) | |
except (ValueError, TypeError): | |
return [thelist] | |
newlist = [list() for i in range(n)] | |
for i, val in enumerate(thelist): | |
newlist[i%n].append(val) | |
return newlist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment