so I'm making an agenda.
The attribute of agenda that manages the dictionary is : self.ContactList = {}
Inside this I have the telephone number as key for a contact (which is a class).
The Contact class has an attribute called telephone and other ones including the contact name.
I want a function that lists the contacts in the agenda, however I wanna list them by alphabetical order of the Contacts it contains.
Right now I'm using this to print the contacts (already have overriden the ____str____ of the contact class to allow this):
def listcontacts(self, agenda):
print("Contact List\n")
for tel, contact in agenda.ContactList.items():
print(contact,"\n"*2)
class Contact:
def __init__(self, name, adress, zipcode, telephone):
self.name = name
self.adress = adress
self.zipcode = zipcode
self.telephone = telephone
def __str__(self):
return ( "Name: " + self.name + "\nAdress: " + self.adress + "\nZipCode: " + self.zipcode
+ "\nTelephone: " + self.telephone)