To test if lst1 is a shallow copy of lst2, I did this:
def check_shallow_copy(lst1, lst2):
''' Return True if lst1 is a shallow copy of lst2.
Return False if not.
'''
for idx in range(len(lst1)):
if lst1 == lst2 and id(lst1[idx]) == id(lst2[idx]) and lst1 is not lst2:
return True
else:
return False
However, I don't think this would work if the two lists share a copy of the first element, but not any of the others. How do I change the function so that id(lst1[idx]) has to be the same as id(lst2[idx]) for all the indexes?
Also, I'm still a bit hazy between the differences of shallow and deep copies. If I wanted this function to tests if lst1 is a deep copy of lst2, what modifications should I make?
Thanks!