0
4.8kviews
Write a Python program to check whether tuple is having duplicate items are not
1 Answer
written 2.6 years ago by | • modified 2.6 years ago |
Code:-
t=(12,12,23,54,23,23)
#set method collects unique values
#convert it into tuple & store it in x
x=tuple(set(t))
#compare x and t
if x!=t:
print("Tuple has duplicate values")
else:
print("Tuple has no duplicate values")
Output:-
Tuple has duplicate values
So to find if the tuples have duplicates, convert tuple to set by type casting then compare set and tuple if they appear to same then the tuple has no duplicate values else it has duplicate values.