Skip to content

Instantly share code, notes, and snippets.

@zjyExcelsior
Last active May 11, 2016 08:04
Show Gist options
  • Save zjyExcelsior/a2df7aa40a55493c7140d0aae8392360 to your computer and use it in GitHub Desktop.
Save zjyExcelsior/a2df7aa40a55493c7140d0aae8392360 to your computer and use it in GitHub Desktop.
A replacement method for switch statement in Python
# coding: utf-8
def switch(item):
return {
'one': 1,
'two': 2,
'three': 3
}.get(item, 0)
if __name__ == '__main__':
print switch('one')
print switch('two')
print switch('three')
print switch('default')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment