python - Python 中(不是全部)字典键的最大值

标签 python dictionary

只有键 xywz 在上面的字典中使用 Python?

my_dict = {"a":0, "b":5, "c":3, "x":4, "y":3, "w":2, "z": 1 }

谢谢

最佳答案

你可以试试这个:

my_dict = {"a":0, "b":5, "c":3, "x":4, "y":3, "w":2, "z": 1}
print(max(my_dict[i] for i in ["x", "y", "w", "z"]))

输出:

4

关于python - Python 中(不是全部)字典键的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46494377/

相关文章:

Python zipfile compress_size 返回 'int' 对象不可调用

python - 密码验证在 django-rest-framework 中不起作用

python - 将数据访问到字典 python 列表中

python - 如何从字典键列表中提取特定项目

python - 从 python 字典中获取所有子键的列表

java - 如何在不使用迭代器或集合的情况下迭代 Map?

c++ - 我可以创建 map <string,map<string, int[2]>> 吗?

python - 如何编写 Twisted 客户端插件

python - 从python中的UUID v1中提取时间

python - 使用正则表达式从Python中的SQL查询中删除别名?