Answer the question
In order to leave comments, you need to log in
How to make a method from a list subclass in which there are several dictionaries that will display the value from the key?
class ContactList(list):
def __init__(self, **kwargs):
self.kwargs = kwargs
def search_by_name(self, name):
if name in self.kwargs:
return self.kwargs.values()
all_contacts = ContactList(a=1, b=2, c=3)
print(all_contacts)
all_contacts.search_by_name('c')
#Метод search_by_contact должен вывести 3, но он ничего не выводит а в переменной all_contacts пустой список
#Подскажите как можно решить эту задачу
Answer the question
In order to leave comments, you need to log in
return self.kwargs.values() will return you the values of all keys in the dictionary. You need to change the method like this:
def search_by_name(self, name):
return self.kwargs.get(name)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question