I need to be able to split an integer into a list of n-length evenly.
For example n = 4,
12 -> [0, 0, 1, 2]
1234 -> [1, 2, 3, 4]
12345 -> [1, 2, 3, 45]
123456 -> [1, 2, 34, 56]
1234567 -> [1, 23, 45, 67]
12345678 -> 12, 34, 56, 78]
123456789 -> [12, 34, 56, 789]
I'm sure I went overkill with the number of examples I have given, but it'll help get the point across.
The code that I have used in the past to split items into lists is:
def split(s, chunk_size):
a = zip(*[s[i::chunk_size] for i in range(chunk_size)])
return [''.join(t) for t in a]
but this code only breaks into n-chunks. (Code from StackOverflow, I don't remember the exact post, sorry).
Thanks for the help.