python - Python issubset 在一组集合上
问题描述
我有一套:
>>> x = set()
>>> x.add(frozenset({1}))
>>> x.add(frozenset({2}))
>>> x.add(frozenset({3}))
>>> x
{frozenset({2}), frozenset({3}), frozenset({1})}
我有一个候选集:
>>> y = frozenset({2})
>>> y
frozenset({2})
我想知道我的候选集是否在我的集合中:
>>> y.issubset(x)
False
>>>
为什么这会返回 False?我应该如何确定我的候选集是否在我的集合中?
解决方案
x = set()
x.add(frozenset({1}))
x.add(frozenset({2}))
x.add(frozenset({3}))
print(x)
y = frozenset({2})
print(y in x) # check if candidate set is in set of sets
这应该返回 True
推荐阅读
- java - Junit for 循环执行计数
- javascript - CORS HTTP 标头点
- sql - CASE WHEN 创建具有所有条件结果的重复行(是和否)
- java - android studio中logcat中显示的错误导致应用程序崩溃
- rest - 通过 Powershell 的 ISIM / ITIM REST 连接
- excel - Excel - 根据相同的值定义范围
- java - 如何序列化包含 LAZY 关联的 json
- django - 找不到 Django 2.0 页面,url 模式不匹配
- regex - 值不以字符开头的键值的正则表达式
- sql - 如何将多列 UNPIVOT 分成两列以上?