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若何比拟两个列表的具体内容,更多请存眷资源魔其它相干文章!
标签: Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!