
- 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
Program to find the product of three elements when all are unique in Python
Suppose we have three numbers, x, y, and z, we have to find their product, but if any two numbers are equal, they do not count.
So, if the input is like x = 5, y = 4, z = 2, then the output will be 40, as all three numbers are distinct so their product is 5 * 4 * 2 = 40
To solve this, we will follow these steps −
- temp_set := a new set
- remove := a new set
- for each i in [x,y,z], do
- if i is in temp_set, then
- insert i into the set called remove
- insert i in to the set temp_set
- if i is in temp_set, then
- for each i in remove, do
- delete i from temp_set
- multiplied := 1
- for each i in temp_set, do
- multiplied := multiplied * i
- return multiplied
Let us see the following implementation to get better understanding −
Example
class Solution: def solve(self, x, y, z): temp_set = set() remove = set() for i in [x, y, z]: if i in temp_set: remove.add(i) temp_set.add(i) for i in remove: temp_set.remove(i) multiplied = 1 for i in temp_set: multiplied *= i return multiplied ob = Solution() print(ob.solve(5, 4, 2))
Input
5, 4, 2
Output
40
- Related Articles
- Program to find largest product of three unique items in Python
- Program to find sum of unique elements in Python
- Program to find a list of product of all elements except the current index in Python
- Program to find three unique elements from list whose sum is closest to k Python
- Program to find the largest product of two distinct elements in Python
- Python – Test if all elements are unique in columns of a Matrix
- Program to find length of longest consecutive sublist with unique elements in Python
- Python program to find common elements in three sorted arrays?
- Program to check we can find three unique elements ose sum is same as k or not Python
- Product of unique prime factors of a number in Python Program
- C program to find the unique elements in an array.
- Program to find sum of all elements of a tree in Python
- Python program to find common elements in three lists using sets
- Program to find number of elements in all permutation which are following given conditions in Python
- Check if list contains all unique elements in Python

Advertisements