| Store | Cart

Python List Issue

From: Ron_Adam <rad...@tampabay.rr.com>
Sun, 27 Mar 2005 19:59:11 GMT
On Sun, 27 Mar 2005 09:01:20 GMT, "Nick L" <Fearnot003 at mchsi.com>
wrote:

>I've hit a brick wall on something that I'm guessing is pretty simple but>it's driving me nuts. 

Yes, I've ran across that too a few times.

>    How on earth can I make a complete seperate copy of a list with out it>being a attached to the original in any way shape or form so that I can>modifiy if at will and not worry about the original? 

This routine copies a list of lists.


# Makes a copy of a list of lists
# Containing simple data.
def copylistlist(alist):
    if type(alist) is list:
        copy = []
        for i in alist:
            if type(i) is list:
                i = copylistlist(i)
            copy.append(i)
    return copy

bob = [[[0, 0]]]
final = copylistlist(bob)

print 'bob:'bob
print 'Final:'final


This still doesn't create new items within the new list.  but with
literal data consisting of letters and numbers, it will work.

If you are working with a data tree, you may be able to modify this to
do what you want. Just add a test in the inner loop for the data you
want to modify.


>Any ideas, suggestions, comments are greatly appreciated>thanks>>Nick

Hope that helps.

Ron_Adam

Recent Messages in this Thread
Nick L Mar 27, 2005 09:01 am
Robert Kern Mar 27, 2005 09:09 am
Nick L Mar 27, 2005 07:10 pm
Terry Reedy Mar 27, 2005 05:39 pm
Ron_Adam Mar 27, 2005 07:59 pm
Nick L Mar 28, 2005 04:41 am
Greg Ewing Mar 31, 2005 05:34 am
Messages in this thread