credmark.cmf.types.network.NetworkDict
- class NetworkDict[source]
Bases:
DefaultDict
[Network
,T
],Generic
[T
]A dictionary with network as key. It implements a defaultdict to make it easier to provide default values for missing networks. Key can be Network enum, int or int as str.
``` d = NetworkDict(list, {
Network.Mainnet: [1, 2, 3], Network.Ropsten: [4, 5, 6],
})
print(d[Network.Mainnet]) # [1, 2, 3] print(d[1]) # [1, 2, 3] print(d[“1”]) # [1, 2, 3]
print(d[Network.Optimism]) # [] d[Network.Optimism].append(10) print(d[Network.Optimism]) # [10] ```
Methods
fromkeys
get
pop
Remove and return a (key, value) pair as a 2-tuple.
setdefault
update
Attributes
Factory for default value called by __missing__().
- clear() None. Remove all items from D.
- copy() a shallow copy of D.
- default_factory
Factory for default value called by __missing__().
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- values() an object providing a view on D's values