Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 试图修复我的函数_Python_Loops - Fatal编程技术网

Python 试图修复我的函数

Python 试图修复我的函数,python,loops,Python,Loops,我正在处理一个函数,其中我必须返回一个元组,其中第一个参数是最大数的str,第二个参数是int的列表。下面是我为函数编写的示例和内容: 投票(['G','G','N','G','C']) ('G',[1,3,0,1]) “”“ 必须将maxvalue的位置映射到正确的参与方: parties = ['NDP', 'Green', 'Liberal', 'CPC'] winning_party = parties[total.index(max(total))] 尝试使用计数器计算每个元素获得的

我正在处理一个函数,其中我必须返回一个元组,其中第一个参数是最大数的str,第二个参数是int的列表。下面是我为函数编写的示例和内容:

投票(['G','G','N','G','C']) ('G',[1,3,0,1]) “”“


必须将maxvalue的位置映射到正确的参与方:

parties = ['NDP', 'Green', 'Liberal', 'CPC']
winning_party = parties[total.index(max(total))]

尝试使用
计数器
计算每个元素获得的票数。例如:

from collections import Counter
...
vote_count = Counter(votes_list)
int_list = vote_count.values() # value is [1, 3, 1]
winners = vote_count.most_common() # value is [('G', 3), ('C', 1), ('N', 1)]
如您所见,
计数器
有一个界面,既可以为您提供每个元素的投票计数,也可以按投票的降序为您提供所有元素。

与?