Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28952
| Received | by 10.224.220.12 with SMTP id hw12mr4530800qab.8.1347454089500; Wed, 12 Sep 2012 05:48:09 -0700 (PDT) |
|---|---|
| Received | by 10.52.66.235 with SMTP id i11mr2179262vdt.7.1347454089413; Wed, 12 Sep 2012 05:48:09 -0700 (PDT) |
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!nx02.iad01.newshosting.com!newshosting.com!69.16.185.11.MISMATCH!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!v8no3365184qap.0!news-out.google.com!da15ni3445qab.0!nntp.google.com!v8no2099310qap.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Wed, 12 Sep 2012 05:48:09 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=151.64.221.170; posting-account=n6qkFgoAAADlcmXD1gV4JHf3Oaoy7Vgm |
| NNTP-Posting-Host | 151.64.221.170 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <f9d9dfa2-71c6-4b47-9d0a-e6f59c8ab818@googlegroups.com> (permalink) |
| Subject | Boolean function on variable-length lists |
| From | Libra <librarama@gmail.com> |
| Injection-Date | Wed, 12 Sep 2012 12:48:09 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Received-Bytes | 1937 |
| Xref | csiph.com comp.lang.python:28952 |
Show key headers only | 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 | Next — Next in thread | Find similar | Unroll 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