What you want is the different prefixes of a word
def prefixes(word):
return [word[:i + 1] for i in range(len(word))]
print(prefixes("hello")) # ['h', 'he', 'hel', 'hell', 'hello']
print(prefixes("pink")) # ['p', 'pi', 'pin', 'pink']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…