itertools.flatten()? and copying generators/iterators.
Francis Avila
francisgavila at yahoo.com
Tue Oct 28 07:07:43 EST 2003
"Alex Martelli" <aleax at aleax.it> wrote in message
news:Tesnb.57573$e5.2124916 at news1.tin.it...
> Peter Otten wrote:
> ...
> > def keepstrings(seq):
> > if isinstance(seq, basestring):
> > raise TypeError
> > return iter(seq)
> ...
> > The above handles strings in a way that is nonintrusive on client code.
>
> Yes, very nice. I'd make keepstrings the default (one RARELY wants
> to treat strings as nonatomic) AND replace the typetest with an
> attempt to do a seq+'' (if it doesn't raise, seq ain't a string),
> but that's just me:-).
>
> Alex
>
try: seq+'' seems more expensive. Is it just to handle the case where
someone makes a string-alike that doesn't derive from str? (Actually, I
guess that's about all pre-2.2 code.)
Is it expensive enough to even matter?
--
Francis Avila
More information about the Python-list
mailing list