I've got a tuple with items that can be repetitive. I need to extract only unique items.
For example:
tup = ('one', 'one', 'one', 'two', 'two','three',
'four', 'four', 'four', 'five', 'five', 'seven')
I need to get only:
'one', 'two', 'three', 'four', 'five', 'seven' (The order is not important).
How can I check the tuple and get only the values I need?
I came up with this solution but it doesn't take the last item of the tuple.
tup = ('one', 'one', 'one', 'two', 'two',
'three', 'four', 'four', 'four', 'five', 'five', 'seven')
for count, item in enumerate(tup):
if (count+1) == len(tup):
break
if tup[count] != tup[count + 1]:
print(tup[count])
Also this one but it gives the "tuple index out of range' error:
tup = ('one', 'one', 'one', 'two', 'two',
'three', 'four', 'four', 'four', 'five', 'five', 'seven')
i = 0
while len(tup):
if tup[i] != tup[i+1]:
print(tup[i])
i += 1
Thank you in advance!