Question
How to Merge two tuples and remove duplicates in python.
Solution
✔ Verified
Steps:--
- Tuples themselves don’t support removing duplicates directly because they are immutable.
- So, first concatenate the tuples.
- Convert the concatenated tuple into a set to remove duplicates (sets store unique items).
- Convert back to a tuple if you want the result as a tuple.
tuple1 = (1, 2, 3, 4)
tuple2 = (3, 4, 5, 6)
# Merge tuples
merged = tuple1 + tuple2
# Remove duplicates by converting to set, then back to tuple
result = tuple(set(merged))
print(result)Click here to download practice questions on
Python Tuple