Python深度检查器

时间:2018-05-18 13:44:05

标签: python-3.x deep-copy

我正在学习最后一年的考试,似乎有一个问题要求我写一个函数deep_copy_check来检查一个列表是否是另一个列表的深层复制。但是,我不明白下面提供的建议解决方案的条件语句的用途是什么,任何人都可以告诉我为什么有必要添加lst1 != lst2?我觉得if lst1 is lst2足够了。

def deep_copy_check(lst1,lst2):
    if lst1 != lst2 or lst1 is lst2:
        return False
    else:
        result = True
        for i in range(len(lst1)):
            if type(lst1[i]) == list:
                result = result and deep_copy_check(lst1[i],lst2[i])
            else:
                result = result and lst1[i] is lst2[i]
        return result

0 个答案:

没有答案
相关问题