The dictionary gets the value without knowing the key

In python, if I have a dictionary that has one pair of key values, and if I don't know what the key can be, how can I get the value?

(and if I have a dict with more than 1 key, a pair of values, how can I return any of the values ​​without knowing any of the keys?)

+4
source share
1 answer

You just need to use dict.values().

This will return a list containing all the values ​​of your dictionary, without specifying any key.

You can also be moved to:

  • .keys(): returns a list containing keys
  • .items(): returns a list of tuples (key, value)

, Python 3 , .

+15

Source: https://habr.com/ru/post/1615885/


All Articles