Comment

Comment by jpxw

    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?

parent jpxw 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton