时间:2021-07-01 10:21:17 帮助过:59人阅读

思路:(推荐学习: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如何比较两个列表的详细内容,更多请关注Gxl网其它相关文章!