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


Groups > comp.lang.python > #28958

Re: Boolean function on variable-length lists

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'true,': 0.04; 'false,': 0.07; '3),': 0.09; '[1,': 0.09; 'lst': 0.09; 'cc:addr:python-list': 0.10; ':-)': 0.13; '-tkc': 0.16; '1),': 0.16; '2),': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'index.': 0.16; 'lambda': 0.16; 'message-id:@tim.thechases.com': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'subject:variable': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'bit': 0.21; 'import': 0.21; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; '>>>>': 0.29; 'value)': 0.29; 'writes:': 0.29; 'subject:lists': 0.32; 'could': 0.32; 'list': 0.35; 'false': 0.35; 'follows:': 0.35; 'skip:z 10': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'apply': 0.39; 'subject:-': 0.40; 'more': 0.63; 'obvious': 0.71; 'received:50.22': 0.84
Date Wed, 12 Sep 2012 08:18:59 -0500
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16
MIME-Version 1.0
To Jussi Piitulainen <jpiitula@ling.helsinki.fi>
Subject Re: Boolean function on variable-length lists
References <f9d9dfa2-71c6-4b47-9d0a-e6f59c8ab818@googlegroups.com> <qotwqzzjswb.fsf@ruuvi.it.helsinki.fi>
In-Reply-To <qotwqzzjswb.fsf@ruuvi.it.helsinki.fi>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
X-Source
X-Source-Args
X-Source-Dir
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.556.1347455871.27098.python-list@python.org> (permalink)
Lines 40
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347455871 news.xs4all.nl 6909 [2001:888:2000:d::a6]:34646
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28958

Show key headers only | View raw


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 and apply it to the values as follows:
> 
>>>> cs = [ lambda x : x >= 1, lambda x : x <= 3, lambda x : x == 2,
> ...        lambda x : x >= 3 ]

This can even be decoupled a bit more for dynamic creation:

>>> lst = [1,2,3,4]
>>> import operator as o
>>> conditions = [
...     (o.ge, 1),
...     (o.le, 3),
...     (o.eq, 2),
...     (o.ge, 3),
...     ]
>>> [op(v, constraint) for ((op, constraint), v) in zip(conditions,
lst)]
[True, True, False, True]
>>> all(compare(value, constraint) for ((compare, constraint),
value) in zip(conditions, lst))
False

Note that you'd also want to check len(conditions)==len(lst) for
obvious reasons. :-)

-tkc



Back to comp.lang.python | Previous | NextPrevious in thread | Next 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