TypeError: '<' not supported between instances of 'set' and 'tuple'
TypeError: '<' not supported between instances of 'set' and 'tuple'
我不断收到以下错误:TypeError: '<' not supported between instances of 'set' and 'tuple'
,我不确定为什么?
这是我的代码:
print(reduce(lambda x,y: x<y, set(list(map(tuple,list1))), set(list(map(tuple,list2)))))
如果我对问题的理解正确,可能的简化是:
set(map(tuple, list1)).issubset(set(map(tuple, list2)))
或使用您的符号:
set(map(tuple, list1)) < set(map(tuple, list2))
一些备注:
- 无需构建那些中间列表。
set
可以接受一个可迭代对象,就像 list
做的那样
- 您只需要检查一次集合是否是另一个集合的子集。 Reduce 在这里没有意义
我不断收到以下错误:TypeError: '<' not supported between instances of 'set' and 'tuple'
,我不确定为什么?
这是我的代码:
print(reduce(lambda x,y: x<y, set(list(map(tuple,list1))), set(list(map(tuple,list2)))))
如果我对问题的理解正确,可能的简化是:
set(map(tuple, list1)).issubset(set(map(tuple, list2)))
或使用您的符号:
set(map(tuple, list1)) < set(map(tuple, list2))
一些备注:
- 无需构建那些中间列表。
set
可以接受一个可迭代对象,就像list
做的那样 - 您只需要检查一次集合是否是另一个集合的子集。 Reduce 在这里没有意义