itertools.flatten()? and copying generators/iterators.

Alex Martelli aleax at aleax.it
Tue Oct 28 06:17:07 EST 2003


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





More information about the Python-list mailing list