In this python tuple program, we will test whether a tuple is distinct or not.
Steps to solve the program
- Take a tuple as input.
- Create a set of input tuple it will remove the duplicate elements.
- Now check whether the length of the tuple is equal to the length of the new tuple i.e. length of set of tuple using an if-else statement.
- If they are equal then the tuple is distinct else the tuple is not distinct.
- Print the output.
tup = (1,2,3,4)
if len(set(tup)) == len(tup):
print("Tuple is distinct")
else:
print("Tuple is not distinct")
Output :
Tuple is distinct
tup1 = (3,4,5,4,6,3)
if len(set(tup1)) == len(tup1):
print("Tuple is distinct")
else:
print("Tuple is not distinct")
Output :
Tuple is not distinct