ListWithCortege = [(2, 4, 2, 1, 0), (4, 2, 1, 0), (1, 1, 0), (4, 1), (1, 4, 1)]
for item in ListWithCortege:
print(item)
for element in item[0:2]:
print(element)
dict = {
(2,4):'1',
(4,2):'2',
(2,1):'3',
(1,0):'4',
(1,1):'5',
(4,1):'6'
}
结论:
(2, 4, 2, 1, 0)
2
4
(4, 2, 1, 0)
4
2
(1, 1, 0)
1
1
(4, 1)
4
1
(1, 4, 1)
1
4
请告诉我如何从元组的元素中获取交替的数字对?
[((2,4),(4,2),(2,1),(1,0)), ((4,2),(2,1),(1,0)), ((1,1),(1,0)), (4,1), ((1,4),(4,1)) )]
然后可以将它们与字典键的值进行比较吗?
您可以使用
zip
:UPD(如果列表中有数字则有效
UPD 2通过添加配对值来处理单例元组: