I'm doing dictionaries in python now, and im trying to access the profile.keys
and profile.items
commands. All that happens though is something like <dict_values object at 0x107fa50>
shows up. What should i do?
you have to call like this profile.keys()
and profile.items()
. They are methods.
If you omit the brackets, you don't actually call the function. Instead you get a reference to the function object.
>>> mydict = {'foo':'bar'}
>>> mydict.keys
<built-in method keys of dict object at 0x01982540>
>>> mydict.keys()
['foo']
>>>
If you want to iterate over keys:
for x in profile.keys():
print x
or values
for x in profile.values():
print x
or key-value pairs:
for x, y in profile.items():
print x, y
or just assign to a variable for later use
x = profile.items()
etc.
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