3 ms·
I frequently use the latter in Python. I like that it's easy to construct programatically (because it's data) and it more explicitly handles the various cases (
by lucian1900 15y ago
I frequently use the latter in Python. I like that it's easy to construct programatically (because it's data) and it more explicitly handles the various cases (especially the default case).
- dpritchett 15y agoAgree, I do it a lot as a way of selecting functions in a switch statement: handlers = { 'dave' : call_dave(), 'ted' : call_ted(), 'julie' : contact('julie') } handlers['dave']() # Call dave handlers['julie']() # Contact julie [handlers[person]() for person in ['dave', 'julie', 'ted']] # Contact all three