Last active
September 10, 2017 09:39
-
-
Save voroninman/72fae0bfa774ff54e382a236036b0624 to your computer and use it in GitHub Desktop.
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 Category(object): | |
def __init__(self, slug=None): | |
self.slug = slug | |
def __repr__(self): | |
return self.slug | |
categories = [ | |
Category(slug='b'), | |
Category(slug='d'), | |
Category(slug='c'), | |
Category(slug='a'), | |
] | |
order = ['a', 'b', 'c'] | |
categories = sorted(categories, | |
key=lambda c: order.index(c.slug) if c.slug in order else len(order)) | |
print(categories) | |
# [a, b, c, d] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment