Skip to content

Instantly share code, notes, and snippets.

@sloria
Last active December 24, 2022 20:04
Show Gist options
  • Select an option

  • Save sloria/5895768 to your computer and use it in GitHub Desktop.

Select an option

Save sloria/5895768 to your computer and use it in GitHub Desktop.
class Book:
...
def __lt__(self, other):
return (self.author, self.title) < (other.author, other.title)
@vindavs

vindavs commented Mar 1, 2014

Copy link
Copy Markdown

How about this to reduce duplication (makes sense if there are many variables)

class Book:
    def tupled():
        return (self.author, self.title)

    def __lt__(self, other):
        return self.tupled() < other.tupled()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment