Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28952

Boolean function on variable-length lists

Newsgroups comp.lang.python
Date 2012-09-12 05:48 -0700
Message-ID <f9d9dfa2-71c6-4b47-9d0a-e6f59c8ab818@googlegroups.com> (permalink)
Subject Boolean function on variable-length lists
From Libra <librarama@gmail.com>

Show all headers | View raw


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] == 2
L[3] >= 3

In this case, the function returns 0 because the third constraint is not satisfied. 

With fixed-length lists, I can sometimes use a very naive approach and hard-code the constraints combined with AND. Nonetheless, the problems are:
1) even with fixed-length lists, the hard-code approach requires a lot of effort (especially with long lists) and is prone to error;
2) the constraints may change, so with a hard-code approach the effort grows exponentially;
3) I need to work on variable-length lists (generally, lists of numbers).

I can't figure out anything useful.
Could you please suggest me a suitable ways?
 
Thanks
Libra  

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Boolean function on variable-length lists Libra <librarama@gmail.com> - 2012-09-12 05:48 -0700
  Re: Boolean function on variable-length lists Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-09-12 16:02 +0300
    Re: Boolean function on variable-length lists Tim Chase <python.list@tim.thechases.com> - 2012-09-12 08:18 -0500
    Re: Boolean function on variable-length lists Libra <librarama@gmail.com> - 2012-09-12 06:19 -0700
      Re: Boolean function on variable-length lists Libra <librarama@gmail.com> - 2012-09-12 06:33 -0700
      Re: Boolean function on variable-length lists Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2012-09-12 16:37 +0300
        Re: Boolean function on variable-length lists Ken Seehart <ken@seehart.com> - 2012-09-12 06:51 -0700
        Re: Boolean function on variable-length lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-12 15:29 +0100
        Re: Boolean function on variable-length lists MRAB <python@mrabarnett.plus.com> - 2012-09-12 16:55 +0100
  Re: Boolean function on variable-length lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-12 13:11 +0000
    Re: Boolean function on variable-length lists Libra <librarama@gmail.com> - 2012-09-12 06:25 -0700

csiph-web