I have a string
ddffjh3gs
I want to convert it into a list
["ddf", "fjh", "3gs"]
In groups of 3 characters as seen above. What is the best way to do this in python 2.7?
I have a string
ddffjh3gs
I want to convert it into a list
["ddf", "fjh", "3gs"]
In groups of 3 characters as seen above. What is the best way to do this in python 2.7?
Using list comprehension with string slice:
>>> s = 'ddffjh3gs'
>>> [s[i:i+3] for i in range(0, len(s), 3)]
['ddf', 'fjh', '3gs']