RE: Itertools wishlists

From: Robert Brewer (fumanchu_at_amor.org)
Date: 03/14/05


Date: Mon, 14 Mar 2005 09:53:18 -0800
To: <python-list@python.org>

Steven Bethard wrote:
> Ville Vainio wrote:
> > A simpler API:
> >
> > def flatten(sequence, atomic_test = lambda o:
> isinstance(o,basestring)):
> > """ don't recurse into iterables if atomic_test -> True """
>
> Yes, this is also the API I would have suggested. Simple,
> but flexible enough to handle the odd cases with the occasional
> user-defined iterable non-containers.

If there are two or three common atomic_test's they could also be placed
into itertools globals (with better names, of course ;):

def is_string(item):
    return isinstance(item, basestring)

def flatten(seq, atomic_test = is_string):
    ...

Perhaps atomic_test could allow a tuple or list of tests and combine
them...?

Robert Brewer
MIS
Amor Ministries
fumanchu@amor.org



Relevant Pages

  • Re: Automatic Generation of Python Class Files
    ... Steven Bethard a écrit: ... This could be necessary if you have an existing API that used public attributes, but changes to your code require those attributes to do additional calculations now. ... There are cases where you *really* have - by 'design' I'd say - the semantic of a property, but know from the start you'll need computation. ...
    (comp.lang.python)
  • Re: Itertools wishlists
    ... Ville Vainio wrote: ... this is also the API I would have suggested. ... enough to handle the odd cases with the occasional user-defined iterable ... STeVe ...
    (comp.lang.python)