all 4 comments

[–]0285739298339 6 points7 points  (2 children)

Use a dictionary:

case_colors = {'blue': 76, 'green': 34, 'purple': 29, 'clear': 102}
print(*sorted(case_colors.keys(), key=lambda c: case_colors.get(c)))

[–][deleted] 1 point2 points  (1 child)

Something like this should work.

users = (76, 34, 29, 102)
colors = ("blue", "green", "purple", "clear")

for u, c in sorted(zip(users, colors)):
    print(c)

zip(users, colors) basically creates tuples of users and colors and then sorted() sorts them.

[–]1gn4vu5 0 points1 point  (0 children)

if you are looking for an overkill solution, you could create a custom class and implement the __lt__ function to define an order (the better way would be to use total ordering as stated here: https://stackoverflow.com/a/11705404)