공부
[Python] Split string every nth character?
승가비
2021. 9. 11. 08:53
728x90
>>> line = '1234567890'
>>> n = 2
>>> [line[i:i+n] for i in range(0, len(line), n)]
['12', '34', '56', '78', '90']
https://stackoverflow.com/questions/9475241/split-string-every-nth-character
Split string every nth character?
Is it possible to split a string every nth character? For example, suppose I have a string containing the following: '1234567890' How can I get it to look like this: ['12','34','56','78','90']
stackoverflow.com
728x90