我需要在python中创建两个列表,如下所示 a = ['my','name','Green','Dev'] b = ['绿色','白色']
现在我需要比较列表并打印常用词
输出应该是 绿色 任何人都可以给我完整的代码导入库。 谢谢
答案 0 :(得分:0)
试试这个:
for word in a:
if word in b:
print(word + "\n)
如果您使用的是python 2.7,则打印命令应该是print word + "\n"
(即括号中没有)
答案 1 :(得分:0)
a = ['my','name','Green','Dev']
b = ['Green','White']
common = set(a) & set(b)
for x in common:
print x
答案 2 :(得分:0)
a = ['my','name','Green','Dev']
b = ['Green','White']
common = [ item for item in a if item in b ]