Python Enum: Display all the member name of an enum class ordered by their values
Write a Python program to display all the member names of an enum class ordered by their values.
Sample Solution:
Python Code:
import enum
class Country(enum.IntEnum):
Afghanistan = 93
Albania = 355
Algeria = 213
Andorra = 376
Angola = 244
Antarctica = 672
print('Country Name ordered by Country Code:')
print('\n'.join(' ' + c.name for c in sorted(Country)))
Sample Output:
Country Name ordered by Country Code: Afghanistan Algeria Angola Albania Andorra Antarctica
Flowchart:
Visualize Python code execution:
The following tool visualize what the computer is doing step-by-step as it executes the said program:
Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to iterate over an enum class and display individual member and their value.
Next: Write a Python program to get all values from an enum class.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics