【发布时间】:2023-01-26 19:13:17
【问题描述】:
使用列表和元组创建两个 zip。
x1=[1,2,3]
y1=[4,5,6]
x2=(1,2,3)
y2=(4,5,6)
w1=zip(x1,y2)
w2=zip(x2,y2)
比较它们:
w1 == w2
False
用list函数显示值,它们包含相同的值,为什么w1==w2是False?
list(w1)
[(1, 4), (2, 5), (3, 6)]
list(w2)
[(1, 4), (2, 5), (3, 6)]
【问题讨论】:
-
将它们包装在 set() set(w1) == set(w2) 中
-
这回答了你的问题了吗? Compare two lists of tuples
-
因为您是在比较两个不同的对象,而不是它们的内容。
-
请尝试使用
list(w1) == list(w2),zip没有适当的相等性。
标签: python python-zip