在用户输入的列表中计算最常用的名称?

时间:2018-06-20 02:45:27

标签: python-3.x

所以我的问题是这样的,来自用户创建的列表。名称的数量也由他们选择。看起来像这样。 (为代码道歉)。

from collections import Counter
inputcount = int(input("Enter number of players."))
count = 1
list_of_integers = []
playerno = 1
while count <= inputcount:
    appendinput = str(input("Enter name of player no %s: "%(playerno)))
    list_of_integers.append(appendinput)
    playerno += 1
    count += 1
    cnt = Counter(list_of_integers)

print(cnt.most_common())

在输出中,它显示了所有输入及其计数,但是我需要它仅显示重复性最高的输入及其计数。我必须使用一个函数来查找最常见的元素。

0 个答案:

没有答案
相关问题