- 1
Fuzzy Search #need help
#I need help!!! # i want print second value and " Not found" if it not in dictionary contacts = { "David": ["123-321-88", "david@test.com"], "James": ["241-879-093", "james@test.com"], "Bob": ["987-004-322", "bob@test.com"], "Amy": ["340-999-213", "a@test.com"] } #your code goes here a=input() b=contacts.get(a,"Not found") print(b)
9 Antworten
+ 6
b=contacts.get(a,[0,"Not found"])[1]
+ 1
So [1] is the element of value of it
Thank you...
0
Looks good, what's wrong?
0
I mean second value, print out Second value of dictionary, you can see email right there
0
They want only email not include number phone
0
contacts.get(a,"Not found") return a list, so you see
0
Use judgment statements
or
replace the "Not found" with a list like [None, "Not found"]
0
Simba
Others always told me don't write the code of result directly instead of guiding him/her to think about the solution.
0
If a in contacts:
print (contacts[a][1])
else:
print ("Not found")