Skip to content

Instantly share code, notes, and snippets.

@axil
Last active April 16, 2022 19:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axil/c2553f44fbba406cb63320c67bbc7d4a to your computer and use it in GitHub Desktop.
Save axil/c2553f44fbba406cb63320c67bbc7d4a to your computer and use it in GitHub Desktop.
subclass_tuple
class Point(tuple):
def __new__(cls, x, y):
return super().__new__(cls, (x, y))
@property
def x(self):
return self[0]
@property
def y(self):
return self[1]
def __repr__(self):
return f'Point({self.x}, {self.y})'
>>> points = [Point(1,2), Point(2,3), Point(1,2)]
>>> Counter(points)
Counter({Point(1, 2): 2, Point(2, 3): 1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment