python 比较两个list

参考1 https://blog.csdn.net/weixin_44151034/article/details/124286429

 

参考 2 参考代码

def is_diff_ele(list1, list2):
    """
    判断两个列表元素是否一致(不是两个列表是否相同)
        True: 一致; False: 不一致
    """
    set1 = set2 = set()
    if list1:
        set1 = set(list1)
        list1 = list(set1)
    if list2:
        set2 = set(list2)
        list2 = list(set2)
    if len(list1) != len(list2):
        return False
    for i in list1:
        if i not in set2:
            return False
    for j in list2:
        if j not in set1:
            return False
    return True

 

posted @ 2022-08-26 18:17  tslam  阅读(234)  评论(0编辑  收藏  举报