python取字典的第一个键值
作者:野牛程序员:2023-12-19 09:02:09python阅读 2875
使用Python获取字典的第一个键值对可以通过以下方式实现:
dictionary = {'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}
first_key = next(iter(dictionary))
first_value = dictionary[first_key]
print(first_key, first_value)上述代码中,next(iter(dictionary))用于获取字典的第一个键,然后通过dictionary[first_key]获取对应的值。
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892

- 上一篇:python列表最小值
- 下一篇:python字典获取最大值的键的值
