Iterate over dictionary of objects

后端 未结 1 370
日久生厌
日久生厌 2021-01-17 21:46

I have a dictionary of objects which contains the "Names/Ranges" within a spreadsheet. As I process the spreadsheet I need to update the value associated with a r

1条回答
  •  Happy的楠姐
    2021-01-17 22:13

    for foo in some_dict iterates through the keys of a dictionary, not its values.

    d = {'a': 1, 'b': 2, 'c': 3}
    for dd in d:
        print(dd)
    # gives a; b; c
    

    You probably want to do for foo in some_dict.values()

    for dd in d.values():
        print(dd)
    # gives 1; 2; 3
    

    0 讨论(0)
提交回复
热议问题