Dynamic comparison operators
Jussi Piitulainen
jpiitula at ling.helsinki.fi
Thu May 24 10:45:32 EDT 2012
Alain Ketterlin writes:
> mlangenhoven at gmail.com writes:
>
> > I would like to pass something like this into a function
> > test(val1,val2,'>=')
> >
> > and it should come back with True or False.
>
> def test(x,y,c):
> return c(x,y)
>
> Call with: test(v1,v2, lambda x,y:x<=y ). A bit noisy imho.
Re noisy:
import operator as o
test(v1, v2, o.le)
More information about the Python-list
mailing list