python如何比较两个列表

python中两个列表的比较

思路:(推荐学习:Python视频教程)

首先判断列表是否等长;

如果等长,判断对应索引位置的值是否相同;

如果不同,记录两者的误差值和索引值

代码如下:

def compare(list1, list2):    error = []    error_index = []    if len(list1) == len(list2):        for i in range(0, len(list1)):        #两个列表对应元素相同,则直接过            if list1[i] == list2[i]:                pass            else:#两个列表对应元素不同,则输出对应的索引                error.append(abs(list1[i]-list2[i]))                # print(i)                error_index.append(i)    print(error)    print(error_index)

更多Python相关技术文章,请访问Python教程栏目进行学习!

以上就是python如何比较两个列表的详细内容,更多请关注其它相关文章!

【文章转自:防御服务器 aqt.html提供,感恩】在你生活出现失意和疲惫时能给你一点儿力量和希冀,只愿你幸福快乐。

python如何比较两个列表

相关文章:

你感兴趣的文章:

标签云: