Is there a way to get the value of the key, not the key value in a dictionary? for example:
d = {"testkey": "testvalue"}
print(d.get("testkey"))
#OUTPUT: "testvalue"
Is there a way to get the String "testkey"? I will have no way of knowing what the String returned will be in the end. Would it be more beneficial to use a list instead of a dictionary?
You are looking for the keys()
function (used as d.keys()
).
You may also use this:
for key in d:
print "key: %s , value: %s" % (key, d[key])
for all the information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With