Michele Simionato <michele.simion...@gmail.com> writes: > On Feb 12, 6:22 pm, MRAB <goo...@mrabarnett.plus.com> wrote: >> Michele Simionato wrote: >> > On Feb 12, 5:07 pm, TechieInsights <gdoerm...@gmail.com> wrote: >> >> On Feb 12, 9:03 am, Catherine Heathcote >> >> >> <catherine.heathc...@gmail.com> wrote: >> >>> But I just cant find it. How do I do an or, as in c/c++'s ||? Just >> >>> trying to do something simple, the python equivilent of: >> >>> if(i % 3 == 0 || i % 5 == 0) >> >>> Thanks. >> >> in 2.5 and above you can do >> >> if any(i%3 == 0, i%5 == 0) >> >> > You are missing a few parenthesis: if any([i%3 == 0, i%5 == 0]) (but >> > the idiomatic solution is to use or). >> >> any() is really only useful with a generator, otherwise you're always >> evaluating both conditions, unlike the solution with 'or'. > > Indeed.
any(f() for f in (lambda: i % 3 == 0, lambda: i % 5 == 0)) :-) -- http://mail.python.org/mailman/listinfo/python-list