python frozenset 是一个不同的hashable objects的无序集合。 frozenset是一个不可变的集体, 因此在创建后不能修改其内容。

    1. class set([iterable])
    2. class frozenset([iterable])
    3. Return a new set or frozenset object whose elements are taken from iterable. The elements of a set must be hashable. To represent sets of sets, the inner sets must be frozenset objects. If iterable is not specified, a new empty set is returned.
    4. Instances of set and frozenset provide the following operations:
    5. len(s)
    6. Return the number of elements in set s (cardinality of s).
    7. x in s
    8. Test x for membership in s.
    9. x not in s
    10. Test x for non-membership in s.
    11. isdisjoint(other)
    12. Return True if the set has no elements in common with other. Sets are disjoint if and only if their intersection is the empty set.
    13. issubset(other)
    14. set <= other
    15. Test whether every element in the set is in other.
    16. set < other
    17. Test whether the set is a proper subset of other, that is, set <= other and set != other.
    18. issuperset(other)
    19. set >= other
    20. Test whether every element in other is in the set.
    21. set > other
    22. Test whether the set is a proper superset of other, that is, set >=
    23. other and set != other.
    24. union(*others)
    25. set | other | ...
    26. Return a new set with elements from the set and all others.
    27. intersection(*others)
    28. set & other & ...
    29. Return a new set with elements common to the set and all others.
    30. difference(*others)
    31. set - other - ...
    32. Return a new set with elements in the set that are not in the others.
    33. symmetric_difference(other)
    34. set ^ other
    35. Return a new set with elements in either the set or other but not both.
    36. copy()
    37. Return a new set with a shallow copy of s.
    1. In [4]: vowels = ['1', 'a', 'b','.']
    2. In [5]: fs = frozenset(vowels)
    3. In [6]: fs
    4. Out[6]: frozenset({'.', '1', 'a', 'b'})
    5. In [7]:
    6. In [7]: vowels_tuple = (1, 2, 3, 4, 5, 4, 3)
    7. In [8]: fs2 = frozenset(vowels_tuple)
    8. In [9]: fs2
    9. Out[9]: frozenset({1, 2, 3, 4, 5})

    因为frozenset是不可变的,所以没有方法可以改变它的元素。因此,add()、remove()、update()、pop()等函数没有为frozenset定义。