Better create a generator function, like this
>>> def unique_values(iterable):
... seen = set()
... for item in iterable:
... if item not in seen:
... seen.add(item)
... yield item
...
And then you can create a tuple of unique values, like this
>>> tuple(unique_values((1, 2, 3, 3, 4, 4, 5)))
(1, 2, 3, 4, 5)
If you know for sure that the data will be always sorted, then you can avoid creating the set and keep track of the previous data only, like this
>>> def unique_values(iterable):
... it = iter(iterable)
... previous = next(it)
... yield previous
... for item in it:
... if item != previous:
... previous = item
... yield item
>>> tuple(unique_values((1, 2, 3, 3, 4, 4, 5)))
(1, 2, 3, 4, 5)
You can write an iterator object, with a class, like this
>>> class Unique:
... def __init__(self, iterable):
... self.__it = iter(iterable)
... self.__seen = set()
...
... def __iter__(self):
... return self
...
... def __next__(self):
... while True:
... next_item = next(self.__it)
... if next_item not in self.__seen:
... self.__seen.add(next_item)
... return next_item
...
>>> for item in Unique((1, 2, 3, 3, 4, 4, 5)):
... print(item)
...
1
2
3
4
5
You can refer this answer, and the Iterator Types section in Python 3 Data Model documentation