-1

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
4

1 回答 1

2

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
于 2020-03-13T17:47:14.083 回答