Try this way:
>>> s
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
>>> n
5
>>> [int(''.join(str(x) for x in s[i*n: i*n + n])) for i in range(len(s)/n)]
[12345, 678910, 1112131415]
just a suggestion not completely tested code
Edit: To write in a file do like:
>>> L = [''.join(str(x) for x in s[i*n: i*n + n]) for i in range(len(s)/n)]
>>> with open("file", 'w') as f:
... for v in L:
... f.write(v + ', ')
...
I have not cast to int when I write in a file.
Updated: improved code
For loss less split a list of any length you can do ceiling division. I have improved the code and added below:
def split_list(L, n):
"""split successive n-sized groups from L as a list
"""
from math import ceil
parts = int(ceil(len(L)/float(n))) # ceilng division 5/2 ==> 3
return [int(''.join(str(_) for _ in L[i*n: i*n + n])) for i in range(parts)]
Some test-cases
# test cases
n = 5
s = [1, 2, 3 ]
print split_list(s, 5) # output [123]
s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
print split_list(s, 5) # output [12345, 678910, 111213]
s = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
print split_list(s, 5) # output [12345, 678910, 1112131415]