编写python,输入两段英文,将两段英文中都有的单词找出来并存放在一个新的列表后输出?

如题所述

第1个回答  2023-02-15

# 示例代码

text1 = "I like to play basketball and football"

text2 = "I also like to play soccer and tennis"

# 将两段英文转换为列表

list1 = text1.split()

list2 = text2.split()

# 创建一个新的列表

common_words = []

# 遍历两个列表,将两段英文中都有的单词添加到新的列表中

for word in list1:

if word in list2:

common_words.append(word)

# 输出新的列表

print(common_words)

相似回答