, x dict .
:
class myset(MutableSet):
def __init__(self, iterable=()):
self.dictset = {}
self.dictset.update(iterable)
def __bomb__(s, *a, **k): raise NotImplementedError
add = discard = __contains__ = __iter__ = __len__ = __bomb__
:
set: 10 10
frozenset: 10 10
Set: 10 20
myset: 10 10
update , iterable , Python , . , dict , . dict(mapping), genex. , , . dict.fromkeys(mapping, default_val): , , , . , ; , , .
, , , - . , , , .
, : . :
, Python , , . Python , , , . Python . __hash__ . ( , Python - .)
- , , dict, . Python. , .
Python , dict, 1 ; , ! , . fromkeys Python, , - 2 , . , Python fromkeys, ; . . .
- - . , dict, , .
>>> a = dict((hash_counting_int(x), []) for x in range(10))
>>> [x.count for x in a.keys()]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> b = dict(a)
>>> [x.count for x in a.keys()]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> for n, v in enumerate(b.itervalues()):
... v.append(n)
...
>>> [x.count for x in a.keys()]
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
>>> b
{0: [0], 1: [1], 2: [2], 3: [3], 4: [4], 5: [5], 6: [6], 7: [7], 8: [8], 9: [9]}
, , , dict . , , .