Created
September 12, 2015 10:51
-
-
Save un-def/cefec2d4427435f1cf4f to your computer and use it in GitHub Desktop.
`uniq` method mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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