Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to check for redundant combinations in a Python dictionary?
There will never be redundant combinations in a Python dictionary because it is a hashmap. This means that each key will have exactly one associated value with it. This value can be a list or another dict though. So if you try to add a duplicate key like
Example
a = {'foo': 42, 'bar': 55}
a['foo'] = 100
print(a)
Output
This will give the output
{'foo': 100, 'bar': 55}
If you really want multiple values for a single key, then you should probably use a list to be associated with the key and add values to that list.
Advertisements
