0

I got the following dictionary:

    freelancers = {'name': 'freelancing Shop', 'brian': 70, 'black knight': 20, 
                   'biccus diccus': 100, 'grim reaper': 500, 'minstrel': -15}

I want my for statement to loop trough all the dictionary..and if a value that contains the word 'shop' is found. Printing it. Is there any way to do it??.

this is clearly not working, values could be string, int, etc.

for key, value in freelancers.items():
    if 'Shop' in value:
        print(f"Welcome to {value}")

1 Answers1

0

You need to add a type check

for key, value in freelancers.items():
    if isinstance(value, str) and 'Shop' in value:
        print(f"Welcome to {value}")
zanuda
  • 176
  • 1
  • 6