Re: Flattening
- To: mathgroup at yoda.physics.unc.edu
- Subject: Re: Flattening
- From: HAY at leicester.ac.uk
- Date: Sun, 5 APR 92 21:51:19 GMT
I came in late on this and have not kept a record of the original question but does the following meet the specification? finallist = (#//.{b___List} :> b)&/@startlist It is OK on the examples that I have seen (I use Richard Gaylord's tests) f[x_] := (#//.{b___List} :> b)&/@x g[x_] := FixedPoint[ Replace[#,{A___,List[X___List],B___} :> {A,X,B}]&, x ] startlist = {{a,a,a},{a,a},{{b,b},{b,b,b}},{a,a,a,a},{{b,b},{b}}} f[startlist] === g[startlist] True and f[{{{{{{a,b},{c,d}}}}}}] === g[{{{{{{a,b},{c,d}}}}}}] True And it is pretty fast: longstartlist = Table[startlist, {20}]; f[longstartlist];//Timing {0.4 Second, Null} g[longstartlist];//Timing {8.83333 Second, Null} A final check f[longstartlist] === g[longstartlist] True From Allan Hayes Department of Mathematics The University Leicester LE1 7RH U.K. hay at leicester.ac.uk