"Stringizing" a list
Peter Schneider-Kamp
nowonder at nowonder.de
Wed Aug 9 13:51:26 EDT 2000
Cees de Groot wrote:
>
> what's the cleanest way to convert a random nested list structure like:
If you are also interested in speed, then of the three solutions I
have seen proposed (flatten, stringize, stringit) flatten is the
clear winner (I timed it on some bigger list at 2.6s vs 6.0s vs 12.1s).
For the semantics you might want to use
string.join(flatten(thatbloodysequence))
Peter
P.S.: flatten wins because it constructs a list and not hundreds
of immutable strings. stringit is bad because it uses
lisp-style car-cdr recursion (very inefficient when used
with python lists).
--
Peter Schneider-Kamp ++47-7388-7331
Herman Krags veg 51-11 mailto:peter at schneider-kamp.de
N-7050 Trondheim http://schneider-kamp.de
More information about the Python-list
mailing list