这会有帮助吗?
lis = ['hi how are you',
'pretty good',
'the quick brown fox',
'the is quick brown fox play',
'play the quick brown fox']
def requ(text):
# This mimics the request
output = []
for word in text.split():
# This just mimics getting some ID for each word
xyz = "".join(str([ord(x) for x in word])).replace(", ", "")
# This mimics the word root part
if word in ["are", "is"]:
output.append((word, "be", xyz))
else:
output.append((word, word, xyz))
return output
new_lis = [requ(w) for w in lis]
print(new_lis)
输出:
[[('hi', 'hi', '[104105]'), ('how', 'how', '[104111119]'), ('are', 'be', '[97114101]'), ('you', 'you', '[121111117]')], [('pretty', 'pretty', '[112114101116116121]'), ('good', 'good', '[103111111100]')], [('the', 'the', '[116104101]'), ('quick', 'quick', '[11311710599107]'), ('brown', 'brown', '[98114111119110]'), ('fox', 'fox', '[102111120]')], [('the', 'the', '[116104101]'), ('is', 'be', '[105115]'), ('quick', 'quick', '[11311710599107]'), ('brown', 'brown', '[98114111119110]'), ('fox', 'fox', '[102111120]'), ('play', 'play', '[11210897121]')], [('play', 'play', '[11210897121]'), ('the', 'the', '[116104101]'), ('quick', 'quick', '[11311710599107]'), ('brown', 'brown', '[98114111119110]'), ('fox', 'fox', '[102111120]')]]