Assume I have a class called Subject:
class Subject():
def __init__(self, name, longName):
self.name = name
self.long_name = longName
def __repr__(self):
return self.long_name + "(" + self.name + ")"
In my code, I create a bunch of these objects, assign name and long_name, then sort the list alphabetically with
sorted(subjects, key=attrgetter("long_name"))
The list that I get looks like this:
[BETRIEBSWIRTSCHAFT (BW), MATHEMATIK (MA), WIRTSCHAFTSINFORMATIK (WI), WIRTSCHAFTSLEHRE (WW), fio (fio), ÜBUNGSRATHAUS (ÜR)]
Obviously, that's not right. How can I properly sort a list of objects alphabetically by an attribute, taking into account uppercase/lowercase and unicode characters like umlauts?
In the end, the list should look like this:
[BETRIEBSWIRTSCHAFT (BW), fio (fio), MATHEMATIK (MA), ÜBUNGSRATHAUS (ÜR), WIRTSCHAFTSINFORMATIK (WI), WIRTSCHAFTSLEHRE(WW)]