How to split string into groups of N characters in list with Python

1 Answer

0 votes
s = 'python php java'
N = 3
lst = [s[i:i+N] for i in range(0, len(s), N)]

print(lst)


'''
run:

['pyt', 'hon', ' ph', 'p j', 'ava']

'''

 



answered Sep 13, 2018 by avibootz

Related questions

1 answer 183 views
1 answer 164 views
2 answers 199 views
2 answers 232 views
2 answers 244 views
...