我被问到以下问题,并被要求不要使用纽比和熊猫。在
考虑两个列表中给出的班级学生的分数表
Students =['student1','student2','student3','student4','student5','student6','student7','student8','student9','student10']
Marks = [45, 78, 12, 14, 48, 43, 45, 98, 35, 80]
从上面两个列表中,Student[0]
得到{Student[1]
得到{
所以任务就是打印学生的名字
对于前两个问题,我创建了两个列表的字典,以学生为键,标记为值,然后根据值升序和降序排序,但是,我得到了整个升序和降序列表,如何限制我的前5个结果(如mysql lol中的limit 5)
另外,我不知道如何解决第三个问题,你能帮帮我吗?在
请在下面找到我的代码
^{pr2}$
要限制为5个,请添加
[:5]
以仅在sorted
列表的前5个元素上进行交互。在for key, value in sorted(dictionary.items(), key=lambda item: item[1],reverse=True)[:5]:
应该为降序列表做工作。在关于百分位数,这是一个统计问题,但你可以:
然后在这两个值之间显示排序的
(dictionary.items(), key=lambda item: item[1])
的值:sorted(dictionary.items(), key=lambda item: item[1])[first_quartile:third_quartile]
试试这个,不要使用与代码类似的numpy。在
输出
^{pr2}$使用上述函数,通过提供已排序的标记列表来计算百分位值。然后根据百分位值过滤字典。在
上述函数的灵感来自http://code.activestate.com/recipes/511478-finding-the-percentile-of-the-values/
相关问题 更多 >
编程相关推荐