Is it possible to add a key to a Python dictionary after it has been created?
It doesn\'t seem to have an .add() method.
.add()
You can create one:
class myDict(dict): def __init__(self): self = dict() def add(self, key, value): self[key] = value ## example myd = myDict() myd.add('apples',6) myd.add('bananas',3) print(myd)
Gives:
>>> {'apples': 6, 'bananas': 3}