Skip to content
← Back to Community
How Can I implement The 'search' Feature?
Profile icon
SamKunefeh

Hi, I am relatively new to coding and decided to make a telephone directory to practice making and using dictionaries. I have implemented all my desired functions in it but I can't add the 'search for a name'in LINE 48 feature somehow. I have tried it many times with .get() methods and making many variables but it doesn't work. Basically, how it works is, you search for a name and it shows you the person's phone number from the directory. Any help on this feature or suggestions for improving my code would be appreciated.

Thanks!

Answered by CoolJames1610 [earned 5 cycles]
View Answer
Voters
Profile icon
CoolJames1610
Profile icon
SamKunefeh
Comments
hotnewtop
Profile icon
CoolJames1610

make the list of searchable items in a list and do

if search_input in (list):

maybe this is what u r looking for :D

Profile icon
SamKunefeh

Thanks CoolJames1610!!! I tried to implement your suggestion, but unfortunately there was some kind of error. But it also gave me another idea, to make a function that looks through the dictionary.
So, I made a new function.

def search_name_directory(search_input):
search_split = search_input.split(" ")
search_output = ""
for name in search_split:
search_output += directory.get(name, name)
print(search_output)

Profile icon
CoolJames1610

Ah happy you found something! @Jackbaklava