I am trying to build a dictionary for a discord bot. The data structure will look like this:
poll = {
'LINK' : {'MoonRaccoon' : 1, 'TheDirtyTree' : 1},
'ZRX' : {'MoonRaccoon' : 1, 'Dontcallmeskaface' : 1, 'TheDirtyTree' : 1},
'XRP' : {'Dontcallmeskaface' : 1},
'XLM' : {'aeon' : 1, 'Bob' : 1}
}
this will then be saved to db["poll"] in the Repl.it database. https://docs.repl.it/misc/database which i guess is just a persistent dictionary? (I don't think this is relevant to the issue I'm having though)
users will enter their vote like
!v ZRX
The bot then needs to add that "vote" to the dictionary.
The code I am trying to get to do that goes like so:
update:
def update_poll(ticker,requestor):
vote = {ticker : {requestor : 1}}
for (key, value) in vote.items():
if 'poll' not in db.keys():
db['poll'] = []
if key in db['poll'].keys():
db['poll'][key].append(value)
else:
db['poll'][key] = value
it's not going well though.. Some have previously suggested using defaultdict
but i honestly have not been able to wrap my brain around it yet. python novice here..
any suggestions would be most appreciated.