- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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}
Advertisements