Skip to content

Instantly share code, notes, and snippets.

@craigderington
Last active September 1, 2016 22:04
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 craigderington/826c08274996fe2a49e9 to your computer and use it in GitHub Desktop.
Save craigderington/826c08274996fe2a49e9 to your computer and use it in GitHub Desktop.
Breaks a list into 'n' pieces horizontally.
#!/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