Skip to content

Instantly share code, notes, and snippets.

@un-def
Created September 12, 2015 10:51
Show Gist options
  • Save un-def/cefec2d4427435f1cf4f to your computer and use it in GitHub Desktop.
Save un-def/cefec2d4427435f1cf4f to your computer and use it in GitHub Desktop.
`uniq` method mixin
class UniqMixin:
def uniq(self):
uniq_list = []
for el in self:
if el not in uniq_list:
uniq_list.append(el)
return self.__class__(uniq_list)
if __name__ == '__main__':
class MyTuple(UniqMixin, tuple): pass
l = MyTuple([7, 1, 2, 3, 2, 5, 7, 3])
print(l)
print(l.uniq())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment