Oct-03-2023, 01:26 AM
Hello!
Given ist the dictionary "telefonbook" with telefon-Nr. as the key, and with vorname, name, adress as the parameters to the keys.
I'm trying to write a programm which with the funktion "searchName" with an given name also all rest parameter printed.
What I doing wrong?:
Given ist the dictionary "telefonbook" with telefon-Nr. as the key, and with vorname, name, adress as the parameters to the keys.
I'm trying to write a programm which with the funktion "searchName" with an given name also all rest parameter printed.
What I doing wrong?:
telefonbook = { '52307': {'vorname': 'Max', 'name': 'Mustermann', 'adress': 'poststr. 15'}, '25758': {'vorname': 'Thom','name': 'Swenson', 'adress': 'bethastr. 37'}, '01579': {'vorname': 'Jeff', 'name': 'Peters', 'adress': 'sportstr. 584'} } def searchName(telefonbook, name): """Durchsucht ein Adressbuch nach einem Namen. Durchsucht die Dictionary-Objekte eines Adressbuchs, ob ein Name in deren Werten vorkommt. Arguments: telefonbook (dict): Das Adressbuch, welches durchsucht werden soll name (str): Der Name, nach dem gesucht wird Returns: dict: Ein Teiladressbuch mit den gefundenen Adressen und vornamen """ results = {} for item in telefonbook.items(): person = item[1] if name in person.values(): results[item[0]] = person return results ergebnis = searchName(telefonbook, 'Swenson') print(ergebnis)