class ContactList(list):
"""
Class - list of contacts
"""
# method search
def search(self, name):
"""
Search name in list of contacts
:param name:
:return: list
"""
matching_contacts = []
for contact in self:
if name in contact.name:
matching_contacts.append(contact)
return matching_contacts
class Contact:
"""
Class - contact
"""
all_contacts = ContactList()
def __init__(self, name, email):
"""
Constructor
:param name:
:param email:
"""
self.name = name
self.email = email
self.all_contacts.append(self)
if __name__ == '__main__':
c1 = Contact("John A", "johna@example.net")
c2 = Contact("John B", "johnb@example.net")
c3 = Contact("Jenna C", "jennac@example.net")
print([c.name for c in Contact.all_contacts.search('John')])