Is there a dedicated way to get the number of items in a python `Enum`? Is there a dedicated way to get the number of items in a python `Enum`? python-3.x python-3.x

Is there a dedicated way to get the number of items in a python `Enum`?


Yes. Enums have several extra abilities that normal classes do not:

class Example(Enum):    this = 1    that = 2    dupe = 1    those = 3print(len(Example))  # duplicates are not counted# 3print(list(Example))# [<Example.this: 1>, <Example.that: 2>, <Example.those: 3>]print(Example['this'])# Example.thisprint(Example['dupe'])# Example.thisprint(Example(1))# Example.this


Did you try print(len(Mood)) ?