is_iterable function.
Neil Cerutti
horpner at yahoo.com
Wed Jul 25 15:42:53 EDT 2007
On 2007-07-25, Marc 'BlackJack' Rintsch <bj_666 at gmx.net> 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:
try:
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