How can I extract all values from a dictionary in Python?

前端 未结 11 2013
难免孤独
难免孤独 2020-11-30 17:56

I have a dictionary d = {1:-0.3246, 2:-0.9185, 3:-3985, ...}.

How do I extract all of the values of d into a list l?

11条回答
  •  感动是毒
    2020-11-30 18:32

    To see the keys:

    for key in d.keys():
        print(key)
    

    To get the values that each key is referencing:

    for key in d.keys():
        print(d[key])
    

    Add to a list:

    for key in d.keys():
        mylist.append(d[key])
    

提交回复
热议问题