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


Groups > comp.lang.python > #28964

Re: Boolean function on variable-length lists

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ken@seehart.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; '(at': 0.03; 'argument': 0.04; 'def': 0.10; '(f,': 0.16; 'function?': 0.16; 'index.': 0.16; 'lambda': 0.16; 'pairs': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject:variable': 0.16; 'wrote:': 0.17; 'creates': 0.18; '>>>': 0.18; 'define': 0.20; 'putting': 0.20; 'anonymous': 0.22; 'wednesday,': 0.22; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'values': 0.26; 'am,': 0.27; 'structures': 0.27; 'value)': 0.29; 'writes:': 0.29; 'function': 0.30; 'subject:lists': 0.32; 'could': 0.32; 'print': 0.32; 'defining': 0.33; 'function.': 0.33; 'right?': 0.33; 'true.': 0.33; 'values.': 0.33; 'to:addr:python- list': 0.33; 'list': 0.35; 'false': 0.35; 'follows:': 0.35; 'there': 0.35; '12,': 0.36; "didn't": 0.36; 'possible': 0.37; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'subject:-': 0.40; 'containing': 0.61; 'more': 0.63; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'actually,': 0.84; 'returns.': 0.84; 'understand,': 0.84
Date Wed, 12 Sep 2012 06:51:46 -0700
From Ken Seehart <ken@seehart.com>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120907 Thunderbird/15.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Boolean function on variable-length lists
References <f9d9dfa2-71c6-4b47-9d0a-e6f59c8ab818@googlegroups.com> <qotwqzzjswb.fsf@ruuvi.it.helsinki.fi> <c90042ac-d6b8-4fe2-8174-3de1462a3537@googlegroups.com> <qotsjanjrag.fsf@ruuvi.it.helsinki.fi>
In-Reply-To <qotsjanjrag.fsf@ruuvi.it.helsinki.fi>
Content-Type multipart/signed; protocol="application/pkcs7-signature"; micalg=sha1; boundary="------------ms060607090500060108030907"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To ken@seehart.com
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.560.1347457996.27098.python-list@python.org> (permalink)
Lines 139
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347457996 news.xs4all.nl 6899 [2001:888:2000:d::a6]:33955
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28964

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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, data1)




On 9/12/2012 6:37 AM, Jussi Piitulainen wrote:
> 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 each value in
>> the list (at least 1 constraint for each value)
> Either you write more complex constraint functions, or you use more
> complex data structures to hold them.
>
>>>>>> 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?
> The value of each lambda expression is a function. f(x) is a function
> call, evaluated for each pair (f, x) from the list of pairs that the
> zip returns.
>
> { ... for ... in ... } creates a set of the values, no duplicates.
> [ ... for ... in ... ] creates a list of the values.
>
>>> {False, True}
>> Actually, I don't understand the output. Why it is both False and
>> True?
> It's a set containing False and True. The False comes from the f(x)
> where f = lambda x : x == 2, and x is 3. There is only one True
> because I requested a set of the values.


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