Too much code - slicing

Carl Banks pavlovevidence at gmail.com
Sat Sep 18 22:09:33 EDT 2010


On Sep 17, 1:01 pm, Andreas Waldenburger <use... at geekmail.INVALID>
wrote:
> On Thu, 16 Sep 2010 16:20:33 -0400 AK <andrei.... at gmail.com> wrote:
>
> > I also like this construct that works, I think, since 2.6:
>
> > code = dir[int(num):] if side == 'l' else dir[:-1*int(num)]
>
> I wonder when this construct will finally start to look good.

I don't know if it'll ever look good, per se, but it looks better when
it's used in rule-exception sort of case:

    something = rule if condition else exception

Then the "tacked-on" feel the "if condition else exception" part works
because it is actually tacked on.

Apart from occasions like this and throwaway one-liners I use regular
if-then statements.  If Python had added the C-like a ? b : c, then
I'd use it a lot more, since that version is not inherently
unbalanced.


Carl Banks



More information about the Python-list mailing list