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 in Python by Neel
• 3,010 points
29 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 by Arvind
• 2,960 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 in Python by Anjali
45 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 in Python by Neel
• 3,010 points
29 views
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 in Python by SDeb
• 13,160 points
22 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 289 views
+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 in Python by Arvind
• 2,960 points
23 views
0 votes
1 answer