字典在不知道键的情况下获得价值 [英] Dictionary get value without knowing the key

查看:62
本文介绍了字典在不知道键的情况下获得价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在python中,如果我有一个具有单个键值对的字典,并且如果我不知道键可能是什么,那么如何获得该值?

In python if I have a dictionary which has a single key value pair and if I don't know what the key might be, how can I get the value?

(如果我的字典中有多个键,值对,那么如何在不知道任何键的情况下返回任何一个值?)

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

推荐答案

您只需使用 dict.values() .

You just have to use dict.values().

这将返回一个列表,其中包含字典的所有值,而无需指定任何键.

This will return a list containing all the values of your dictionary, without having to specify any key.

您可能也有兴趣:

请注意,在Python 3中,返回值实际上不是正确的列表,而是查看对象.

Note that in Python 3, returned value is not actually proper list but view object.

这篇关于字典在不知道键的情况下获得价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆