我正在编写一个从两个列表中打印常见项目的代码
def compare_lists_same(list3, list4):
common =[j for j in list4 if j in list3]
return common
A = ['beef','chicken','steak','fish','plants', 1, 2]
B = ['plants','steak','cheese', 1, 2, 3, 4, 5]
ignore_case = False
print('First list:'+str(A))
print('Second list'+str(B))
C = compare_lists_same (A,B)
print('The common items from the lists are'+str(C))
这将打印“列表中的常见项目是 ['plants', 'steak', 1, 2]”
我如何告诉函数打印没有整数的列表,所以只会打印 str