How can I get dictionary key as variable directly in Python (not by searching from value)?

前端 未结 14 1799
面向向阳花
面向向阳花 2020-12-04 06:19

Sorry for this basic question but my searches on this are not turning up anything other than how to get a dictionary\'s key based on its value which I would prefer not to us

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 06:51

    For python 3 If you want to get only the keys use this. Replace print(key) with print(values) if you want the values.

    for key,value in my_dict:
      print(key)
    

提交回复
热议问题