如何将字符串拆分为2个字母的单词。就像给定的字符串是“ HelloThere”一样,现在我想将其设置为“ [He”,“ ll”,“ oT”,“ he”,“ re”]。请帮助在python中进行编码。
答案 0 :(得分:0)
yourList = []
yourString = "HelloThere"
while yourString:
yourList.append(yourString[:2])
yourString = yourString[2:]
如果打印您的列表,您将得到结果。