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,
On 12/09/2012 14:51, Ken Seehart wrote:
[snip]
Could you please not top post on this list, thanks.
--
Cheers.
Mark Lawrence.
--
http://mail.python.org/mailman/listinfo/python-list
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)})
constraints = [gt(2), eq(1)]
data0 = [1,1]
data1 = [3,1]
print constrain(constraints, data0)
print constrain(constraints, da
On 12 September 2012 14:25, Libra wrote:
> On Wednesday, September 12, 2012 3:11:42 PM UTC+2, Steven D'Aprano wrote:
> > On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote:
>
> > > I need to implement a function that returns 1 only if all the values in
> > > a list satisfy given constraints (at leas
Libra writes:
> 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
On Wednesday, September 12, 2012 3:19:28 PM UTC+2, Libra wrote:
> > {False, True}
> Actually, I don't understand the output. Why it is both False and True?
Ok, I have understood now, I didn't noticed it was a set and not a list.
Regards
--
http://mail.python.org/mailman/listinfo/python-list
On Wednesday, September 12, 2012 3:11:42 PM UTC+2, Steven D'Aprano wrote:
> On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote:
> > I need to implement a function that returns 1 only if all the values in
> > a list satisfy given constraints (at least one constraint for each
> > element in the list),
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
l
On 09/12/12 08:02, Jussi Piitulainen wrote:
> Libra writes:
>> For example, I may have a list L = [1, 2, 3, 4] and the following
>> constraints:
>> L[0] >= 1
>> L[1] <= 3
>> L[2] == 2
>> L[3] >= 3
>
> So you would associate each constraint with an index. You could
> maintain a list of constraints
On Wed, 12 Sep 2012 05:48:09 -0700, Libra wrote:
> Hello,
>
> I need to implement a function that returns 1 only if all the values in
> a list satisfy given constraints (at least one constraint for each
> element in the list), and zero otherwise.
What are the restrictions on the constraints them
Libra writes:
> Hello,
>
> I need to implement a function that returns 1 only if all the values
> in a list satisfy given constraints (at least one constraint for
> each element in the list), and zero otherwise.
>
> For example, I may have a list L = [1, 2, 3, 4] and the following
> constraints:
Hello,
I need to implement a function that returns 1 only if all the values in a list
satisfy given constraints (at least one constraint for each element in the
list), and zero otherwise.
For example, I may have a list L = [1, 2, 3, 4] and the following constraints:
L[0] >= 1
L[1] <= 3
L[2] ==
12 matches
Mail list logo