Skip to content

Instantly share code, notes, and snippets.

@zzstoatzz
Created February 14, 2024 00: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 zzstoatzz/c5b1ffc8fcabbbd6318e5670b0c18db5 to your computer and use it in GitHub Desktop.
Save zzstoatzz/c5b1ffc8fcabbbd6318e5670b0c18db5 to your computer and use it in GitHub Desktop.
from enum import Enum
import marvin
class Fruit(str, Enum):
apple = "apple"
cherry = "cherry"
orange = "orange"
banana = "banana"
@marvin.fn
def rank_fruit(fruit: list[Fruit], order_by: str) -> list[Fruit]:
"""return the indices of the fruit in the enum according to their order"""
if __name__ == "__main__":
rank_fruit(list(Fruit), "alphabetical")
# [<Fruit.apple: 'apple'>, <Fruit.banana: 'banana'>, <Fruit.cherry: 'cherry'>, <Fruit.orange: 'orange'>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment