[Python-Dev] conditional expressions?

Anders J. Munch andersjm at dancontrol.dk
Tue Oct 16 12:56:35 CEST 2001


"Michael Abbott" <michael at rcp.co.uk> wrote in message
news:Xns913C6BFA94D38michaelrcpcouk at 194.238.50.13...
> "Anders J. Munch" <andersjm at dancontrol.dk> wrote in
> news:3bcbfda6$0$42081$edfadb0f at dspool01.news.tele.dk:
>
> > Quick, what does this snippet do if return_as_map is true?
> >
> >  return if return_as_map then {'A':a,'B':b} else a,b
> >
> > Rather than open up a new venue of obfuscation possibilities in
> > Python, I'd go for mandatory parentheses around the conditional
> > expression.
>
> Nah.  Go for "maximal munch", I can't think of anything wrong with that.
> The above expression then returns the dictionary (only).

Good try.  Maximal munch is certainly one of the better options, but
it's not perfect.  What should be the output from:

    x = 260
    abs_x_mod_256 = divmod(if x<0: -x else: +x, 256)[1]
    print abs_x_mod_256

wir-brauchen-maximal-munch-oder-vielleicht-was-anders-munch-ly-y'rs,
Anders





More information about the Python-list mailing list