Let's suppose we find ourselves in a situation where we have no other option than to write a lengthy if-else statement (definitely not something that would make cleaner by polimorphism).
def inevitable_long_if (n):
if n == 0:
elif n == 1:
elif n == 2:
Can we re-write it so that we do not use IFs?
d = collections.defaultdict(lambda : functools.partial(print, 'Manu-manu'))
d = functools.partial(print, 'Zero')
d = functools.partial(print, 'One')
d = functools.partial(print, 'Two')
Now, let's call some to see how it works:
d() ==> Zero
d() ==> One
d() ==> Two
d() ==> Manu-manu
The first version is 9 lines long, the second one (without imports) is 4 lines long. To me, the second version is also much more readable, but you decide.