Printing only duplicates from a list

I have a hospital management system (I am the admin).

But, I want to be able to print a list of just ONLY the surnames of the same patients, for example in the main it displays 2 people with the same surname “smith”, i want to create a option where I can print all the details of those within the same family.

In short form, how do I retrieve the information of patients with the same surname in my program & create a list of just those with the same attribute?

I’ll explain the purpose of each class

the admin class is majority of the code for the program.

the main is for calling functions & stores the patients details in a list.

the patient class stores the functions such as surname, firstname etc of the patients.

Main: from Admin import Adminfrom Doctor import Doctorfrom Patient import Patient - Pastebin.com
I’ve got 2 more classes, but I wasn’t able to post them as I am a new member

Patient: class Patient: def __init__(self, first_name, surname, age, mobile, postc - Pastebin.com

Also a sidenote: I’ve come up with a solution but unsure if its plausible, this is the code

def group_family(self,patients):

family = (“Smith”)

print(*filter(patients, lambda p: p.get_surname() == family), sep=‘\n’)

However, I am running into the error: TypeError: ‘function’ object is not iterable

You have the arguments reversed. First the boolean functions, then the iterable. But even better is a comprehension. I believe the following should work.

print(*[p for p in patients if p.get_surname()  == family])