[英]Python dict get value fastest way
Is this the best way to get the value/key of someID
. 这是获取someID
的值/键的最佳方法someID
?
I want to separate the keys and values I receive: 我想分开收到的键和值:
items={'someID': 2,}
for item in items:
key = item
print(key)
value = items.get(item)
print(value)
This works, but is this the correct/fastest way in Python 3.4? 这可行,但这是Python 3.4中正确/最快的方法吗?
You can use the items() method to iterate over the keys and values. 您可以使用items()方法迭代键和值。
d = {1:2, 3:4, 5:6}
for key, value in d.items():
print(key, value)
Better is 更好的是
for key, value in items.items():
print (key)
print (value)
Then you don't need getting values 那你就不需要获取价值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.