Flatten... or How to determine sequenceability?

Noel Rappin noelrap at yahoo.com
Fri May 25 10:44:57 EDT 2001


I'm writing code that needs to flatten a multi-dimension list or tuple into 
a single dimension list.

[1, [2, 3], 4] => [1, 2, 3, 4]

As part of the algorithm, I need to determine whether each object in the 
list is itself a sequence or whether it is an atom.  Using the types module 
would cause me to miss any sequence-like object that isn't actually the 
basic type.  So, what's the best (easiest, most foolproof) way to determine 
whether a Python object is a sequence?

Thanks,

Noel Rappin


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com





More information about the Python-list mailing list