Python dictionaries-How to keep the new value from overwriting the previous value?

前端 未结 4 629
孤独总比滥情好
孤独总比滥情好 2020-12-21 10:02

I want to create a Dictionary called \"First\" (as in First Name) that will store numerous first names which are all stored in the dictionary via a function. The idea is th

4条回答
  •  别那么骄傲
    2020-12-21 10:07

    Turn data['Names']['first'] in a list and append to it:

    data['Names'] = {}
    data['Names']['first'] = []
    
    def store(data, value):
        data['Names']['first'].append(value)
    

提交回复
热议问题