On Mon, May 21, 2012 at 10:37 PM, Roy Smith <r...@panix.com> wrote: > The above code works, but it occurs to me that I could use the much > shorter: > > def experience_text(self): > return dict(CHOICES).get("self.level", "???") > > So, the question is, purely as a matter of readability, which would you > find easier to understand when reading some new code? Assume the list > of choices is short enough that the cost of building a temporary dict on > each call is negligible. I'm just after style and readability here.
Is there a reason not to keep the dictionary around? That would surely be the most logical thing to do. (With, of course, no quotes around self.level.) But out of your two options, I'd go with the loop. It's clear what you're doing and doesn't fiddle around with multiple translations. Chris Angelico -- http://mail.python.org/mailman/listinfo/python-list