Good evening guys,
for my homework i have to implement a class called 'car' which consists of certain parameters like 'registration', 'color', 'manufacturer', 'model' with with output and comparison methods. After this i have to implement a bubble sort to sort these instances by 'manufacturer' and 'model'; the other attributes are neglectable.
my Code so far:
def class car():
self.__init__(self, registration, color, manufacturer, model):
self.registration = registration
self.color = color
self.manufacturer = manufacturer
self.model = model
def output(self):
return '{}{}{}{}'.format(self.registration, self.color, self. manufacturer, self.model)
def bubblesort(list_1):
for k in range(len(list_1)-1, 0, -1):
for i in range(0,k):
if list_1[i] > list[i+1]:
list_1[i], list_1[i+1] = list_1[i+1], list_1[i]
return list_1
what i have to do now is two create an instance of car like this:
instance = [Car(2003, 'black', 'BMW', 'M4')
Car(2005, 'red', 'Audi', 'Q3')
Car(2010, 'green', 'BMW', 'X1')
Car(2007, 'pink', 'Subaru', 'BRZ')]
Car(1998, 'black', 'Audi', 'Q5')
and after sorting it has to look like this:
[Car(2005, 'red', 'Audi', 'Q3')
Car(1998, 'black', 'Audi', 'Q5')
Car(2003, 'black', 'BMW', 'M4')
Car(2010, 'green', 'BMW', 'X1')
Car(2007, 'pink', 'Subaru', 'BRZ')]
So I have pretty much everything but i don't know how to sort 'the whole instance' - actually i don't even know if you can say this...:D
Maybe some of you guys can help me out; thanks.