I have some elements in a list in one class. I want them sorted in a new list, and they have to be sorted by an attribute from another class.
Can anyone give an example?
My code so far looks like this:
class Carcompany:
def __init__(self, model, production_number):
self.model = model
self.production_number = production_number
self.car_list = []
def add_car_to_car_list(self, car):
self.car_list.append(car)
class Info:
def __init__(self):
self.license_plate_number = []
def add_license_plate_to_list(self, license_plate):
self.license_plate_number.append(license_plate)
I need self.car_list to be sorted by self.license_plate_number - highest number first. I don't know how much I'm missing to get there. I appreciate any help I can get :)
car1is a list if you're usingappend()to add a license plate number to it -- but previous you said the list was["car1", "car2", "car3"]which is a list of strings. Please show the classes and lists involved (by editing your question). - martineau