小编Den*_*rno的帖子

如何获取字典中最大值的键,如果有重复,还返回最大的数字键

(抱歉标题含糊)

dic = {1:20, 2:20, 3:20, 4:10}
Run Code Online (Sandbox Code Playgroud)

我希望它返回 3,因为这是字典中三个重复值之间的最高键号。

我目前拥有的是:

return max(dic, key = dic.get)
Run Code Online (Sandbox Code Playgroud)

但这不会得到我想要的结果并将返回 1

python dictionary max duplicates

2
推荐指数
1
解决办法
34
查看次数

如何在python中使用int()将数字四舍五入到其最小值

我想要的是:

if 1700 / 1000 = 1.7 = int(1) # I want this to be True
   lst.append("T")
Run Code Online (Sandbox Code Playgroud)

我的原始代码是:

if 1700 / 1000 == int(1) # This is False and I want it to be True
   lst.append("T")
Run Code Online (Sandbox Code Playgroud)

if 语句为 False,因为答案是 1.7 而不是 1。我希望这是真的。所以我希望使用 int 将 1.7 向下舍入为 1,以便 if 语句为 True。

python truncate rounding

-1
推荐指数
1
解决办法
93
查看次数

标签 统计

python ×2

dictionary ×1

duplicates ×1

max ×1

rounding ×1

truncate ×1