"Stringizing" a list
Peter Schneider-Kamp
nowonder at nowonder.de
Wed Aug 9 18:36:36 EDT 2000
Mike Fletcher wrote:
>
> Something like the following:
>
> import types
> allowedMap = { types.ListType:1, types.TupleType:1 }
Okay, that works. Still the fastest version (for this
particular task) seems to be the following:
def flatten(alist):
result=[]
for element in alist:
if type(element) in (ListType, TupleType):
result.extend(flatten(element))
else:
result.append(element)
return result
Contrary to what I wrote in another posting,
' '.join(flatten(thisNestedList))
is even faster than the non-recursive version.
Peter
--
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