How to add or increment a dictionary entry?

前端 未结 6 849
时光取名叫无心
时光取名叫无心 2020-12-04 16:19

I\'m currently re-engaging with Python after a long absence and loving it. However, I find myself coming across a pattern over and over. I keep thinking that there must be a

6条回答
  •  感情败类
    2020-12-04 16:56

    I don't know how this was tried, but if you need to append items in dict keys...

    indicatorDict = {}
    indicatorDict[0] = 'Langford'
    indicatorDict[1] = 'Esther'
    indicatorDict[3] = 14
    

    Append items to it, be it iteratively or other types:

    indicatorDict[0] = np.append(indicatorDict[0],'Auditorium')
    indicatorDict[1] = np.append(indicatorDict[1],'Duflo')
    indicatorDict[3] = np.append(indicatorDict[3],'November') 
    

    Printing ...

    {0: array(['Langford', 'Auditorium'], dtype='

    I avoided 3rd key in Dict to show that if needed keys can be jumped from one step to another... :) Hope it helps!

提交回复
热议问题