[Tutor] flattening a list

Chad Crabtree flaxeater at yahoo.com
Thu Jan 13 03:28:27 CET 2005


The only problem with this if it is to big or to deeply nested then
it 
will overflow the stack?

Mario Rol wrote:

> nice and concise, found on comp.lang.python:
>
> def flatten(a):
>    if not isinstance(a,(tuple,list)): return [a]
>    if len(a)==0: return []
>    return flatten(a[0])+flatten(a[1:])
>
> _________________________________________________________________
> Play online games with your friends with MSN Messenger 
> http://messenger.msn.nl/
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - 250MB free storage. Do more. Manage less. 
http://info.mail.yahoo.com/mail_250


More information about the Tutor mailing list