is_iterable function.

Neil Cerutti horpner at
Wed Jul 25 21:42:53 CEST 2007

On 2007-07-25, Marc 'BlackJack' Rintsch <bj_666 at> wrote:
> So there's no reliable way to test for "iterables" other than
> actually iterate over the object.

A TypeError exception is perhaps too generic for comfort in this
use case:

def deeply_mapped(func, iterable):
  for item in iterable:
      for it in flattened(item):
        yield func(it)
    except TypeError:
      yield func(item)

I'd be more confortable excepting some sort of IterationError (or
using an is_iterable function, of course). I guess there's always
itertools. ;)

Neil Cerutti

More information about the Python-list mailing list