【发布时间】:2019-12-14 01:08:41
【问题描述】:
我正在尝试创建一个函数,它需要 2 个列表列表和一个整数作为输入:
list1 = [[2, 47, -42], [-42, 29, -45], [24, -11, 18], [-34, -4, -14], [-42, -45, 49], [-21, -6, 12]]
list2 = [[13, 15, -11], [35, -5, -42], [-42, 29, -45], [-48, 8, 26], [-42, 29, -45]]
integer = -42
首先,使用 -42 作为变量检查 list1 中的元组,然后使用 -42 检查 list2 中相同元组的计数。 对于上面的例子,输出应该是:2 as
In list1(tuple with -42): [[2, 47, -42],[-42, 29, -45],[-42, -45, 49]]
list2(similar tuples):[[-42, 29, -45],[-42, 29, -45]]
count: 2
我到现在为止的尝试:
res = sum(x == y for x, y in zip(list1,list2))
上面的代码没有给出任何结果。
【问题讨论】:
标签: python python-3.x list lambda tuples