Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You got that containment backwards;

  switch('a', {'abc': 1}, 'default') #returns 1
... but you're not wrong, that's godawful. But from the context of the article, they're optimizing for the case where multiple cases evaluate to the same answer. It would make more sense to write

  switch('a', {('a','b','c'): 1}, 'default') #returns 1
I'd optimize for performance, personally:

  def switch(match, dictionary, default="no match"):
    return dictionary.get(match, default)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: