Boolean function on variable-length lists

MRAB python at mrabarnett.plus.com
Wed Sep 12 11:55:40 EDT 2012


On 12/09/2012 14:51, Ken Seehart wrote:
> Putting a few of peoples ideas together...
>
>
> gt = lambda x: lambda y: x>y
> eq = lambda x: lambda y: x==y
>
> def constrain(c,d):
>      return all({f(x) for f, x in zip(c, d)})
>
If you're going to use 'all', why use a set?

     return all(f(x) for f, x in zip(c, d))

This will stop as soon as a constraint fails.

> constraints = [gt(2), eq(1)]
> data0 = [1,1]
> data1 = [3,1]
>
> print constrain(constraints, data0)
> print constrain(constraints, data1)
>




More information about the Python-list mailing list