Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.