python - Adding frozenset to set of other frozensets
问题描述
I am trying to add a frozenset to an already existing set of frozensets however when i try to use the add() function to add it the return is None. I tried using the update() function instead but to no avail. I am forced to use frozensets because I need a set of sets and this seems like the only solution in Python. The literal is just a list of one element of type String.
print(literal)
print(clauses)
clauses = clauses.add(frozenset(literal))
print(clauses)
The output looks like this:
['!y']
{frozenset({'!y', 'z', 'x'})}
None
解决方案
The general rule (https://docs.python.org/3/library/stdtypes.html)
The methods that add, subtract, or rearrange their members in place, and don’t return a specific item, never return the collection instance itself but None.
That's why:
clauses = clauses.add(frozenset(literal))
means:
clauses.add(frozenset(literal))
clauses = None
推荐阅读
- azure-pipelines - 具有多个代理的 Azure DevOps 2019 部署组:如何将运行部署限制为一个代理?
- java - ScheduledExecutorService 重复更改延迟
- apache-spark - sqlcontext.read.json 和 spark.read.json 有什么区别
- python - 如何等待协程完成并继续其结果?
- java - 拨出电话上的警报对话框不起作用。CallBlocker 实施失败
- javascript - SQLite - 从临时表问题中选择(Ionic v3)
- bash - $((M & ; 0x10000000)) 是什么意思?
- java - 如何在 Java 中读取文本文件中某一行的特定部分?
- matlab - 如何强制 MATLAB 在 GPU 上运行 CNN
- react-native - 调度操作不会自动重新呈现应用程序