0

Hi, can anyone find my mistake

i have a phonebookgiven as the following: phoneBook = [{'first name': 'Sophia', 'last name': 'Thorarensen', 'number': '06508641036'}, {'first name': 'Emma', 'last name': 'Blöndal', 'number': '06504228512'}, {'first name': 'Olivia', 'last name': 'Thorarensen', 'number': '06501126965'}, {'first name': 'Ava', 'last name': 'Hansen', 'number': '06762858077'}, {'first name': 'Isabella', 'last name': 'Olsen', 'number': '06801324090'}, {'first name': 'Evelyn', 'last name': 'Bergmann', 'number': '06805592151'}, {'first name': 'Charlotte', 'last name': 'Andersen', 'number': '06762229010'}, {'first name': 'Liam', 'last name': 'Briem', 'number': '06767141082'}, {'first name': 'Oliver', 'last name': 'Briem', 'number': '06802647719'}, {'first name': 'Noah', 'last name': 'Thorlacius', 'number': '06805539375'}, {'first name': 'William', 'last name': 'Jensen', 'number': '06765392663'}, {'first name': 'James', 'last name': 'Hjaltalín', 'number': '06508393585'}, {'first name': 'Oliver', 'last name': 'Scheving', 'number': '06769395459'}] and i want to write a method which should return a list with only the names which have a unique first name, this is my approach, but it doesn't work right: def uniqueFirstName(listln): foundByFirstname = listIn for i in range(len(listIn)-1): for j in range(len(listIn)-1): if((listIn[j]['first name'] in listIn[i]['first name']) & (i != j) & (listIn[j]['first name'] in foundByFirstname)): foundByFirstname.remove(listIn[j]) return foundByFirstname uniqueFirstName(phoneBook)

19th Dec 2020, 12:10 PM
Christoph Eisele
2 ответов
+ 2
What is `&`? The `and` keyword is used for logical AND.
19th Dec 2020, 12:23 PM
XXX
XXX - avatar
+ 1
wow thank you so much!
19th Dec 2020, 12:34 PM
Christoph Eisele