您可以使用zip:
>>> s='WELCOME'
>>> list(zip(s, s[1:]))
[('W', 'E'), ('E', 'L'), ('L', 'C'), ('C', 'O'), ('O', 'M'), ('M', 'E')]
>>> [''.join(t) for t in zip(s, s[1:])]
['WE', 'EL', 'LC', 'CO', 'OM', 'ME']
>>> word_list = ['WELCOME', 'TO', 'MY', 'B', 'DAY']
>>> for word in word_list:
... print(word, [''.join(t) for t in zip(word, word[1:])])
...
WELCOME ['WE', 'EL', 'LC', 'CO', 'OM', 'ME']
TO ['TO']
MY ['MY']
B []
DAY ['DA', 'AY']
而要得到您想要的清單:
>>> result=[]
>>> for word in word_list:
... result.extend([''.join(t) for t in zip(word, word[1:])])
...
>>> result
['WE', 'EL', 'LC', 'CO', 'OM', 'ME', 'TO', 'MY', 'DA', 'AY']