这个问题是我的家庭作业,我想不出来
您有两个字符串列表,其中包含您选择的内容。 使用循环遍历列表并比较列表元素,并仅显示重复的列表元素(两个列表中都存在该元素)。应显示字符串,即使其中一个使用大写,另一个使用小写或其组合
我不知道为什么它不起作用
animals = ["dog", "bear", "monkey", "bird"]
pets = ["dog", "bird", "cat", "snake"]
print("The original list 1 : " + str(animals))
print("The original list 2 : " + str(pets))
res = [animals.index(i) for i in pets]
print("The Match indices list is : " + str(res))
试试这个(又快又脏):
我对您的代码进行了一些更新,以便它能够适应具有不同大小写(大写/小写)的类似元素
也许这就是你一直在寻找的
比较两个字符串时要使用If语句
相关问题 更多 >
编程相关推荐