Obtaining a value when given a key in python dicionaries

0 votes
Can we obtain the key from a dictionary when a value is provided?
May 31, 2018 in Python by NEET

recategorized Jun 1, 2018 by Sudhir 26 views

1 answer to this question.

0 votes

We cannot. Dictionaries aren't meant to be used that way. You can iterate through the dictionary using iteritems() instead - 

for name, id in list.iteritems():
    if id == search_id:
        print name
answered May 31, 2018 by Nietzsche's daemon
• 4,260 points

Related Questions In Python

0 votes
1 answer

I have a dictonary in python how to access the value field?

dic={"car":["limo","sedan"]} print (dic.keys())    <-----------------------Fetch the key "car" print (dic['car'][0])   <------------------------Fetch ...READ MORE

answered Dec 19, 2018 in Python by Shuvodip
73 views
0 votes
1 answer
0 votes
1 answer

Why am I getting a error when I am printing two different data types in python?

different data type is being used. that ...READ MORE

answered Mar 6 in Python by Mohammad
• 3,060 points
34 views
0 votes
1 answer

can we sort the key value pairs in a dictionary?

we can use OrderedDict import collections result = colections.Orde ...READ MORE

answered Mar 22 in Python by Mohammad
• 3,060 points
20 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 172 views
+4 votes
6 answers
+4 votes
7 answers

Splitting a List into chunks in Python

Here's a generator that yields the chunks ...READ MORE

answered Apr 13, 2018 in Python by Nietzsche's daemon
• 4,260 points
4,035 views
+1 vote
4 answers

Count the frequency of an item in a python list

To count the number of appearances: from collections ...READ MORE

answered Oct 18, 2018 in Python by tinitales
352 views