python - 如何显示输入的数字在哪个位置?

标签 python python-3.x list

我有一个列表,一旦我对它进行排序以找到“最大值”,我需要显示输入该数字的位置

知道怎么做吗?

我编写了这段代码来接收和排序列表,但我不知道如何接收“数据”的初始位置。


liste = []

while len(liste) != 5:
    liste.append (int(input("enter number :\n")))

listeSorted = sorted(liste)
print("the biggest number is : ", listeSorted[-1]) 

最佳答案

不是通过对列表进行排序来查找列表的最大值,而是使用 max 函数:

largest_val = max(list)

要查找列表中第一次出现的值,请使用 .index 方法。

position = list.index(largest_val)

关于python - 如何显示输入的数字在哪个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49720942/

相关文章:

python - 在 OpenCV 的 findContours 方法中重复

python - 为什么我不能使用 Django 管理应用程序的资源

python - Pandas Groupby 唯一多列

python - Mayavi 无法正确渲染实体表面

python - 如何获取每个字符串变体以及每个位置的可能性列表

python - 使用列表循环将变量添加到元组

Python-内部有 nan 条目的两个数组的互相关

python - 尝试做一个程序来替换给定的行,由同一行但全部大写

android - 在 firefox 或任何其他适用于 windows/桌面 linux 的浏览器中像 appstore 一样列出

Java 8 流 : convert comma separated string to the list of abstract Enum