Is there a Python module that already does this?

David Eppstein eppstein at ics.uci.edu
Wed Feb 6 12:44:52 EST 2002


In article <a3rnd1$1a44oq$1 at ID-11957.news.dfncis.de>,
 "Emile van Sebille" <emile at fenx.com> wrote:

> def flatten(ary, rslt):
>     try:
>         flatten(ary[0], rslt)
>         flatten(ary[1:], rslt)
>     except:
>         if ary: rslt.append(ary)
> 
> rslt = []
> flatten(("cat",5,['dog',[3,3,1]],"zoo"), rslt)
> print 'rslt = ',tuple(rslt)

Isn't all that list-copying (ary[1:]) going to make for a very inefficient 
algorithm?
-- 
David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/



More information about the Python-list mailing list