I want to know what is the best way of converting the string into list of string
For Example:
__string = 'ABCDEFGHIJ'
list_string = ['AB', 'CD', 'EF', 'GH', 'IJ']
How to do this?
I want to know what is the best way of converting the string into list of string
For Example:
__string = 'ABCDEFGHIJ'
list_string = ['AB', 'CD', 'EF', 'GH', 'IJ']
How to do this?
[a+b for a, b in (zip(*([iter(text)]*2)))]
# or
[text[i*2:i*2+2] for i in range(len(text)//2)]
# or
import re
re.findall("..?", text) //handles string of odd length
if the string is not even the less char will be missed. can be easily fixed if needed
easy peasy xD
txt= 'ABCDEFGHIJ'
result = [txt[i:i+2] for i in range(0,len(txt),2)]