Re: Can this be written more concisely in a functional style

From: MetalOne (jcb_at_iteris.com)
Date: 11/18/03


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.



Relevant Pages

  • Re: Can this be written more concisely in a functional style
    ... > def any: ... seq): ... > for elt in itertools.ifilterfalse ... > I don't see why it is used (there is no break in the loop) ...
    (comp.lang.python)
  • Re: DLOOKUP FOR NEXT
    ... > My intention is to extract from my table; base, lot, seq and next seq from ... I've included my DLOOKUP query below, ...
    (microsoft.public.access.queries)
  • Re: Can this be written more concisely in a functional style
    ... > def any: ... seq): ... > for elt in itertools.ifilterfalse ... Since the "else" is unnecessary, it disturbs me, I get confused, ...
    (comp.lang.python)
  • Re: a row-level operator for copying?
    ... has historical data. ... these tables are atest and atest_history). ... select a, seq, c ... end loop; ...
    (comp.databases.oracle.misc)
  • Re: Combine Multiple Records
    ... You would have to do it in a loop or in a cursor. ... Declare @MaxSeg smallint ... The example will stock all comments into Seq# = 1 rows and get rid of the ... rest of Seq#. ...
    (microsoft.public.sqlserver.dts)