35-ForLoop_Searching_a_dictionary.py


Sign up Free. Don't forget to check out our challenges, lessons, solve and learn series and more ...


Code Snippet

print("*****Looping through and searching a dictionary*****")


data = ['Obed', 'Jesse', 'David', 'Solomon']

#search = 'c'
search=input("Who are you searching for?")

for name in data:
    if name == search:
        print ("Found it!", name)
        break
# Prints: Found it! ['a', 'c']
                    

Try it yourself