Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28963
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Boolean function on variable-length lists |
| Date | 2012-09-12 16:37 +0300 |
| Organization | University of Helsinki |
| Message-ID | <qotsjanjrag.fsf@ruuvi.it.helsinki.fi> (permalink) |
| References | <f9d9dfa2-71c6-4b47-9d0a-e6f59c8ab818@googlegroups.com> <qotwqzzjswb.fsf@ruuvi.it.helsinki.fi> <c90042ac-d6b8-4fe2-8174-3de1462a3537@googlegroups.com> |
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 | Next — Previous in thread | 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