- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
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.
- Related Articles
- Python program to print all distinct elements of a given integer array.
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Python Program to Remove all digits before given Number
- Java program to print all distinct elements of a given integer array in Java
- C# program to print all distinct elements of a given integer array in C#
- C++ program to find uncommon characters in two given strings
- Python Program to Accept Three Digits and Print all Possible Combinations from the Digits
- Print all n-digit numbers whose sum of digits equals to given sum in C++
- 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++ Program
- Print a number strictly less than a given number such that all its digits are distinct in C++
- Python program to find uncommon words from two Strings
- Python program to print all Disarium numbers between 1 to 100