[Tutor] Are you allowed to shoot camels? [kinda OT]

Alan Gauld alan.gauld at freenet.co.uk
Tue Feb 8 23:04:59 CET 2005


> table = { 'a': 'a', 'b': 'b or c', 'c': 'b or c', 'd': None }
> result = table.get(var, 'default case')
> if result:
>      print result
>
> This, to my mind, is much cleaner -- you're factoring out the
repeated
> code, whether print statement or call to sys.stdout.write(),
reducing
> the complexity of the dict.  You're making flow control much more
> straightforward.  You're making the whole thing easier to read.

Yep, the lambda stuff etc is there on the assumption that we are
trying to do something a tad more interesting than just print the
label - but as it happens printing the label has been hard enough!!

:-)

Alan G.



More information about the Tutor mailing list