how to split a string into words of 2 letters. Like given string is "HelloThere" now i want to make it ["He","ll","oT","he","re"]. Please help to code that in python.
Asked
Active
Viewed 66 times
-1
-
1`ans = [word[i:i+2] for i in range(0,len(word),2)]` – Mitch Jul 26 '18 at 15:01
-
https://stackoverflow.com/help/how-to-ask – dheiberg Jul 26 '18 at 15:05
1 Answers
0
yourList = []
yourString = "HelloThere"
while yourString:
yourList.append(yourString[:2])
yourString = yourString[2:]
If you print yourList, you will get the result.

masonCOD
- 39
- 11