> 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.

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to