Peter Otten wrote:
> def andmap(predicate, items):
> return False not in (predicate(item) for item in items)
>
> def ormap(predicate, items):
> return True in (predicate(items) for item in items)
These are both broken because they imply the test (in e. g. ormap)
if True == predi
[EMAIL PROTECTED] wrote:
> The following works perfectly:
> import operator
> def andmap(b,L):
> return reduce(operator.and_, [b(x) for x in L])
> def ormap(b,L):
> return reduce(operator.or_, [b(x) for x in L])
Note your [b(x) for x in L] evaluates b(x) for all elements of L
before you b
"Joel Hedlund" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>> footnote: if you have a recent Python 2.5 build,
>
> Who would have that? Is it a good idea to use a pre-alpha python version?
The pre-public release version compiles as 'alpha0'. I have the impression
the current al
The following works perfectly:
import operator
def andmap(b,L):
return reduce(operator.and_, [b(x) for x in L])
def ormap(b,L):
return reduce(operator.or_, [b(x) for x in L])
Thanks!
--
http://mail.python.org/mailman/listinfo/python-list
Peter Otten wrote:
> def ormap(predicate, items):
> return True in (predicate(items) for item in items)
should be
def ormap(predicate, items):
return True in (predicate(item) for item in items)
Hmmpf.
Peter
--
http://mail.python.org/mailman/listinfo/python-list
Peter Otten wrote:
> Python 2.5 will feature similar functions any() and all() which seem to have
> a fixed predicate == bool, though.
You cannot write
all(predicate, list)
but
all(predicate(x) for x in list)
Georg
--
http://mail.python.org/mailman/listinfo/python-list
Joel Hedlund wrote:
>> footnote: if you have a recent Python 2.5 build,
>
> Who would have that? Is it a good idea to use a pre-alpha python version?
> Or any unrealeased python version for that matter? I was under the impression
> that
> the recommended way to go for meager developers in python
[EMAIL PROTECTED] wrote:
> def ormap(b,L):
> if True in map(b,L): return True
> else: return False
>
> Is this good enough?
No, because
- (as Felipe observed) it doesn't shortcut, i. e. it always evaluates
b(item) for all items in L.
- it creates a temporary list
- if truthvalue: return T
> footnote: if you have a recent Python 2.5 build,
Who would have that? Is it a good idea to use a pre-alpha python version? Or
any unrealeased python version for that matter? I was under the impression that
the recommended way to go for meager developers in python like myself is to
stick with
Felipe Almeida Lessa wrote:
> The problem is that it will evaluate all possibilities needlessly. Try
> (not tested and 2.4-only):
footnote: if you have a recent Python 2.5 build, you can make them even
shorter:
>>> help(any)
any(...)
any(iterable) -> bool
Return True if bool(x) is True f
> Does python have andmap and ormap:
>
> andmap((lambda t: boolean(t)),L)
>
> gives True if boolean(t) is True for all t in L and False otherwise?
> And
>
> ormap((lambda t: boolean(t)),L)
>
> gives True if boolean(t) is True for some t in L and False o
On 14 Mar 2006 04:23:55 -0800,
[EMAIL PROTECTED] wrote:
> Hello,
> Does python have andmap and ormap:
> andmap((lambda t: boolean(t)),L)
> gives True if boolean(t) is True for all t in L and False otherwise?
> And
> ormap((lambda t: boolean(t)),L)
> gives True if boolean(
Em Ter, 2006-03-14 às 04:23 -0800, [EMAIL PROTECTED] escreveu:
> def andmap(b,L):
> if False in map(b,L): return False
> else: return True
>
> def ormap(b,L):
> if True in map(b,L): return True
> else: return False
>
> Is this good enough?
The problem is that it will evaluate all possibi
Hello,
Does python have andmap and ormap:
andmap((lambda t: boolean(t)),L)
gives True if boolean(t) is True for all t in L and False otherwise?
And
ormap((lambda t: boolean(t)),L)
gives True if boolean(t) is True for some t in L and False otherwise?
One can use a list comprehension like
[x
14 matches
Mail list logo