- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to print all distinct uncommon digits present in two given numbers
When it is required to print all the distinct uncommon digits that are present in two numbers, a method is defined that takes two integers as parameters. The method ‘symmetric_difference’ is used to get the uncommon digits.
Below is a demonstration of the same
def distinct_uncommon_nums(val_1, val_2): val_1 = str(val_1) val_2 = str(val_2) list_1 = list(map(int, val_1)) list_2 = list(map(int, val_2)) list_1 = set(list_1) list_2 = set(list_2) my_list = list_1.symmetric_difference(list_2) my_list = list(my_list) my_list.sort(reverse = True) for i in my_list: print(i) num_1 = 567234 num_2 = 87953573214 print("The value of first number is") print(num_1) print("The value of first number is") print(num_2) distinct_uncommon_nums(num_1, num_2)
The value of first number is 567234 The value of first number is 87953573214 9 8 6 1
A method named ‘distinct_uncommon_nums’ is defined that takes two integers as parameters.
Both these integers are converted to string type, and then they are mapped to integer type, and converted to a list.
It is then converted to a set to retain the unique values of the list.
Then, the ‘symmetric_difference’ method is used to get the uncommon digits in both the lists.
This difference is converted to a list.
It is then sorted in a reverse order.
It is displayed on the console.
Outside the method, two numbers are defined and are displayed on the console.
The method is called by passing the two numbers as parameters.
The output is displayed on the console.
- Python program to print all distinct elements of a given integer array.
- C++ program to find uncommon characters in two given strings
- Find two distinct prime numbers with given product in C++ Program
- Print uncommon elements from two sorted arrays
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Print all n-digit numbers whose sum of digits equals to given sum in C++
- C# program to print all distinct elements of a given integer array in C#
- Java program to print all distinct elements of a given integer array in Java
- Python Program to Accept Three Digits and Print all Possible Combinations from the Digits
- Python program to find uncommon words from two Strings
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Python program to print all Prime numbers in an Interval
- Find two distinct prime numbers with given product in C++
- Print a number strictly less than a given number such that all its digits are distinct in C++