I have an if-elif-else structure with multiple levels, but the last-level else
is always the same statement:
if statement1:
if something:
do_thing()
elif something_else:
if something_something:
do_thing_something()
elif somethingg:
do_thingg()
else:
do_default()
else:
do_default()
else:
do_default()
As you can see, I use do_default()
3 times, and I feel like there's a better way. This would basically be a default
in a switch-case
statement in other languages, but Python does not have switch-case
. I was wondering if there's any other way I could solve this more elegantly/"Pythonically"? Or is the only way to use dicts or implement my own switch-case
?