iterating one key in a python multidimensional associative array

前端 未结 3 505
礼貌的吻别
礼貌的吻别 2021-01-27 17:41

I\'m dynamically creating a 2 dimensional associative array (dictionary?)

I\'m trying to loop through its keys - while keeping one of the indexes constant, so for instan

3条回答
  •  隐瞒了意图╮
    2021-01-27 17:51

    myhash['john'] is itself a dictionary. (You aren't creating a multi-dimensional dictionary, but rather a dictionary of dictionaries.)

    Thus...

    last_names = list(myhash['john'])
    

    or if you want to do something in a loop...

    for last_name in myhash['john']:
        # do something with last_name
    

提交回复
热议问题