Flatten... or How to determine sequenceability?
Leighton Pritchard
lep at aber.ac.uk
Fri May 25 11:52:28 EDT 2001
On Fri, 25 May 2001 10:44:57 -0400, Noel Rappin <noelrap at yahoo.com>
made a brave stab at grammar with:
>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
Funny you should ask this, as there's been a similar thread on the
Python-Tutor list, in which the following link:
http://aspn.activestate.com/ASPN/Mail/msg/python-Tutor:454781
was mentioned. It contains an excellent flatten() function that might
do just what you're looking for.
--
Leighton Pritchard
lep at spamfree.aber.ac.uk
More information about the Python-list
mailing list