Re: Can this be written more concisely in a functional style
From: MetalOne (jcb_at_iteris.com)
Date: 11/18/03
- Next message: A.M. Kuchling: "Re: PEP 321: Date/Time Parsing and Formatting"
- Previous message: Phil Schmidt: "Re: Making a maze...."
- In reply to: Alex Martelli: "Re: Can this be written more concisely in a functional style"
- Next in thread: Michele Simionato: "Re: Can this be written more concisely in a functional style"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Nov 2003 10:52:58 -0800
My intention was that test() return True or False.
So True in itertools.imap(test, xs) is what I was looking for.
I also like the any() function suggested above.
def any(p, seq):
"""Returns true if any element in seq satisfies predicate p."""
for elt in itertools.ifilter(p, seq):
return True
return False
In the itertools.imap version does
<True in> test against a continually growing list, ie.
True in [False]
True in [False, False]
True in [False, False, False]
True in [False, False, False, True]
or does it just apply <in> to the next generated element.
Is the itertools.imap version as efficient as the for loop version?
Thanks.
- Next message: A.M. Kuchling: "Re: PEP 321: Date/Time Parsing and Formatting"
- Previous message: Phil Schmidt: "Re: Making a maze...."
- In reply to: Alex Martelli: "Re: Can this be written more concisely in a functional style"
- Next in thread: Michele Simionato: "Re: Can this be written more concisely in a functional style"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|