简体   繁体   English

将frozenset 添加到一组其他frozenset 中

[英]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.我正在尝试将一个frozenset 添加到一个已经存在的frozensets 中,但是当我尝试使用add() 函数来添加它时,返回是None。 I tried using the update() function instead but to no avail.我尝试使用 update() 函数,但无济于事。 I am forced to use frozensets because I need a set of sets and this seems like the only solution in Python.我被迫使用frozensets,因为我需要一组集合,这似乎是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 )一般规则( 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.添加、减去或重新排列其成员的方法,并且不返回特定项,从不返回集合实例本身而是 None。

That's why:这就是为什么:

clauses = clauses.add(frozenset(literal))

means:方法:

clauses.add(frozenset(literal))
clauses = None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM