0 votes
1 view
in Python by (11.8k points)

Sorry for this essential inquiry yet my searches on this are not turning up something besides how to get a dictionary's key dependent on its value which I would not really like to use as I just need the content/name of the key and am concerned that looking by value may wind up returning at least 2 keys if the dictionary has plenty of entries... what I am attempting to do is this:

mydictionary={'keyname':'somevalue'}

for current in mydictionary:

   result = mydictionary.(some_function_to_get_key_name)[current]

   print result

   "keyname"

The explanation behind this is that I am printing these out to a document and I need to utilize the key name and the value in doing this 

I've seen the technique underneath however this appears to simply return the key's value

get(key[, default])

1 Answer

0 votes
by (24.6k points)

You need to iterate over keys with:

for key in mydictionary:

   print "key: %s , value: %s" % (key, mydictionary[key])

Are you looking for a good python tutorial? Join the python course fast and gain more knowledge in python.

Watch this video tutorial to gain more knowledge in python

Related questions

0 votes
1 answer
asked Jul 3, 2019 in Python by Sammy (47.8k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 2, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...