Reputation: 5
I was wondering if its possible to have a dictionary in which there is 2 keys for the same item. I don't know if I have explained that well but an example of what I mean is bellow
dictionary = {"key_1","key_2" : "value_1"}
This would have 2 keys but lead to the same value
Is there any way i can do this?
Thanks for the help
Upvotes: 0
Views: 34
Reputation: 114
In Python, keys are the elements/items of the dictionary while values are the values paired with these keys, so yeah, you can have two keys whose values are equal but it would be like -
dictionary = {"key_1":"value_1", "key_2":"value_1"}
In case you are asking for a way to use two items together as a key then the answer is tuples
-
dictionary = { ("key_1","key_2"): "value_1" }
Upvotes: 1