Hello, guys! So I recently started learning about python classes and objects.
My new task is to take the following list:
alist = ["four", "three", "five", "one", "two"]
And sort it according to the integer attributes assigned to each word (object) in class Numbers
.
class Numbers(object):
One=1
Two=2
Three=3
Four=4
Five=5
My initial thoughts were to convert alist
into corresponding integers using a for loop
to create a new list that is a copy of alist
- just as integers. But then that’d mean that I would need to perform the first for loop
, sort the new list, then perform another for loop
to convert the integers back into class objects.
I was wondering if there was a simpler way of completing this task.
I hope someone can help me and explain to me what way would work better and why!
Thank you!!