- 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)

15th Jan 2022, 12:05 PM
Sẩm Lâm Bảo Quý
Sẩm Lâm Bảo Quý - avatar
9 Answers
+ 6
b=contacts.get(a,[0,"Not found"])[1]
15th Jan 2022, 12:33 PM
Simba
Simba - avatar
+ 1
So [1] is the element of value of it Thank you...
15th Jan 2022, 12:38 PM
Sẩm Lâm Bảo Quý
Sẩm Lâm Bảo Quý - avatar
0
Looks good, what's wrong?
15th Jan 2022, 12:14 PM
FanYu
FanYu - avatar
0
I mean second value, print out Second value of dictionary, you can see email right there
15th Jan 2022, 12:15 PM
Sẩm Lâm Bảo Quý
Sẩm Lâm Bảo Quý - avatar
0
They want only email not include number phone
15th Jan 2022, 12:16 PM
Sẩm Lâm Bảo Quý
Sẩm Lâm Bảo Quý - avatar
0
contacts.get(a,"Not found") return a list, so you see
15th Jan 2022, 12:16 PM
FanYu
FanYu - avatar
0
Use judgment statements or replace the "Not found" with a list like [None, "Not found"]
15th Jan 2022, 12:23 PM
FanYu
FanYu - avatar
0
Simba Others always told me don't write the code of result directly instead of guiding him/her to think about the solution.
15th Jan 2022, 12:45 PM
FanYu
FanYu - avatar
0
If a in contacts: print (contacts[a][1]) else: print ("Not found")
11th Jul 2022, 6:16 PM
Mutiat Akobi
Mutiat Akobi - avatar