So I have a Person class derived from dict that contains details like first name, last name, and id.
I have the data loaded from a json file into object and instantiated person class per person in the json (about 30 people) and put them in a peopleList list in the following code:
import json
class Person(dict):
def __init__(self, firstname, lastname, personID):
super().__init__()
self.firstname = firstname
self.lastname = lastname
self.personID = personID
peopleList = []
with open('data.json', 'r') as peopleData:
dataObject = json.load(peopleData)
for registrant in dataObject['registrants']:
newperson = Person(registrant["firstname"], registrant["lastname"], registrant["personID"])
peopleList.append(newperson)
Now I'm trying write a function that takes the peopleList and criteria parameter. This function will sort the list based in alphabetical order based on criteria (firstname, or lastname, or even ID)
Trying to use the peopleList.sort() menthod and failing hard with this. Any input from you guys would be greatly appreciated here. :)