In article <502791ea$0$29978$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote:
> for x in (0,) if len(L)%2 else (0, 1): > ... > > which is even more explicit and simpler to read even though it is longer. Ugh. do_stuff() if len(L) % 2 == 0: do_stuff() # reprocess even-length list Sure, it's 3 lines instead of one, but dead-obvious what the intention is. I might even go for: if len(L) % 2: do_stuff() else: do_stuff() do_stuff() There's two problems with all the looping suggestions people have given. One is that the computation of whether you need to do it once or twice is messy. But, but bigger issue is you're trying to warp what's fundamentally a boolean value into a looping construct. That's a cognitive mismatch. -- http://mail.python.org/mailman/listinfo/python-list