list() will convert a tuple to a list, but any elements that are also tuples will stay as such. This utility function fully converts an arbitrary "tuple tree" to a same-structured list.
1 2 3 4 5 6
def deep_list(x): """fully copies trees of tuples to a tree of lists. deep_list( (1,2,(3,4)) ) returns [1,2,[3,4]]""" if type(x)!=type( () ): return x return map(deep_list,x)
Other datatypes are partially handled by this function. However, if you nest lists within tuples within lists, etc, you might get some elements that are references and not copied.
The copy module has been suggested for this type of problem, but it does not perform the tuple->list part of the transformation.