Boolean function on variable-length lists
Libra
librarama at gmail.com
Wed Sep 12 09:19:28 EDT 2012
On Wednesday, September 12, 2012 3:02:44 PM UTC+2, Jussi Piitulainen wrote:
> So you would associate each constraint with an index. You could
> maintain a list of constraints and apply it to the values as follows:
Yes, even though there could be more constraints for each value in the list (at least 1 constraint for each value)
>
> >>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2,
>
> ... lambda x : x >= 3 ]
>
> >>> { f(x) for f, x in zip(cs, [1,2,3,4]) }
Just to understand, with f(x) you are defining a function f with argument x, right? I didn't know it was possible to define functions in this way. Is this a case of anonymous function?
> {False, True}
Actually, I don't understand the output. Why it is both False and True?
> >>> { f(x) for f, x in zip(cs, [1,2,2,4]) }
> {True}
Ok.
Thank you very much
More information about the Python-list
mailing list