def switch(match, dictionary, default="no match"):
for key in dictionary.keys():
if match in key:
switch.last_match = key
return dictionary.get(key)
return default
Using “in” rather than “==“ here seems odd to me, is that intentional?
i.e I’d expect switch(‘abc’, {‘a’: 1}, default=“default”) to return “default”, but under this code it’d return 1, no?
i.e I’d expect switch(‘abc’, {‘a’: 1}, default=“default”) to return “default”, but under this code it’d return 1, no?