Is it possible to create a dictionary with multiple keys for a single value?

0 votes
How to create a dictionary with multiple keys mapped to a single value?
Jul 24, 2019 in Python by Neel
• 3,010 points
50 views

1 answer to this question.

0 votes

One thing that you can do here is to create a dictionary where a single key has multiple values and then reverse it. For example,

dict1 = {"a": [1,2,3], "b": [4]}
dict2 = {value:key for key in dict1 for value in dict1[key]}
dict2
This will give output as - {1: 'a', 2: 'a', 3: 'a', 4: 'b'}
answered Jul 24, 2019 by Arvind
• 2,980 points

Related Questions In Python

0 votes
1 answer

Is it possible to create an array with all values as zero in python?

You can use  np.zeros(4,3) This will create a 4 ...READ MORE

answered May 24, 2019 in Python by Anjali
79 views
0 votes
1 answer

Is it possible to print a string and a variable in a single print statement in Python?

This can be done using simple string ...READ MORE

answered Jul 15, 2019 in Python by Neel
• 3,010 points
80 views
0 votes
1 answer
0 votes
1 answer

Is it enough to only create checksum of a zip package instead of each file?

I assume you are asking about the ...READ MORE

answered May 8, 2019 in Python by SDeb
• 13,230 points
43 views
0 votes
1 answer
+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, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 639 views
0 votes
0 answers
+4 votes
6 answers
0 votes
1 answer

is it possible to create zip of a directory in Python?

Please go through this code. This should ...READ MORE

answered Jul 10, 2019 in Python by Arvind
• 2,980 points
49 views
0 votes
1 answer

Is it possible to read a text file into a string variable and then scrap the newlines?

This can be done easily in Python. ...READ MORE

answered Aug 7, 2019 in Python by Arvind
• 2,980 points
36 views