python的内部min函数 [英] Internal min function of python

查看:59
本文介绍了python的内部min函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果列表中有多个最小项,我需要知道python的min函数如何工作.哪一个需要分钟?说A = [5、3、1、4、1].现在,如果我说A.remove(min(A))哪一个将被删除?第一个1或第二个1?

I need to know how the min function of python works if there are more than one item in a list which are minimum. Which one takes min? Say A = [5, 3, 1, 4, 1]. Now if I say A.remove(min(A)) which one will be removed? The first 1 or the second 1?

推荐答案

在这种情况下,它将删除第一个.在这种情况下,它更多地是关于 list.remove 函数的行为,而不是 min 函数的行为. min 仅返回列表中的最小值,因此它返回整数 1 . list.remove 删除传递给它的参数的最左侧实例.

In this case it will remove the first one. It's more about the behavior of the list.remove function rather than the min function in this case. min just returns the lowest value in the list so it returns the integer 1. list.remove removes the leftmost instance of the parameter passed to it.

此外,如您在处理对象而不是对象时,此答案与上述问题的联系值(即列表而不是整数),则将选择与最小值匹配的第一个.

Also, as answered in this answer to the question that mgilson linked above, if you are dealing with objects rather than values (i.e. lists rather than integers), the first one matching the minimum value will be selected.

这篇关于python的内部min函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆