I need to create a map from twitter status IDs to their author ID. Obviously, each status has exactly one author.
I expected Python collections to have something like uniqdict
class for which d[key] = value
will raise an exception if the key
already has a value different from value
:
class uniqdict(dict):
def __setitem__(self,key,value):
try:
old = super(uniqdict,self).__getitem__(key)
if old != value:
raise ValueError(self.__class__.__name__,key,old,value)
except KeyError:
super(uniqdict,self).__setitem__(key,value)
This looks like a duplicate of Write-once dictionary?
Anyway, I think write-once dictionary is the name you're looking for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With