- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to find difference in keys contained in two Python dictionaries?
We can use set data type to achieve this. Set is an unordered collection and unique and immutable objects. It is used to perform set operations as defined in set theory of mathematics. Symmetric difference operation on two sets yields elements leaving out common elements.
Example
We can build a set object out of keys of two dictionary objects and perform symmetric difference with the help of ^ operator
>>> D1={1:100, 2:200, 3:300} >>> D2={1:1000, 3:300, 5:500} >>> set(D1.keys())^set(D2.keys()) {2, 5}
- Related Articles
- Python - Difference in keys of two dictionaries
- Python - Intersect two dictionaries through keys
- Handling missing keys in Python dictionaries
- Python – Merge Dictionaries List with duplicate Keys
- How do we compare two dictionaries in Python?
- How to merge two Python dictionaries in a single expression?
- Python program to merge two Dictionaries
- How to compare two dictionaries in C#?
- Python Program to get all unique keys from a List of Dictionaries
- How can we merge two Python dictionaries?
- How to create Ordered dictionaries in Python?
- Python Program to Concatenate Two Dictionaries Into One
- How to perform Calculations with Dictionaries in Python?
- How are dictionaries implemented in Python?
- How to merge multiple Python dictionaries?

Advertisements