python去掉最高分和最低分怎么算平均分 您所在的位置:网站首页 去掉最高和最低的平均分怎么算 python去掉最高分和最低分怎么算平均分

python去掉最高分和最低分怎么算平均分

2024-07-05 13:51| 来源: 网络整理| 查看: 265

我将给出一些演示代码:

# -*- coding: utf-8 -*-

import csv

from collections import defaultdict

from statistics import mean

class_file = 'scores.csv'

open_file = open(class_file)

csv_file = csv.reader(open_file)

def main():

# First, use student name to group by all scores, this will

# generate structure like this:

# {

# 'Andrew': [1, 2, 3, 4, 5]),

# 'Luck': [10, 20]),

# }

score_groups = defaultdict(list)

for name, score in csv_file:

score_groups[name].append(int(score))

# Secondary, use the 3 latest socres only

l3_score_groups = [(key, value[-3:]) for key, value in score_groups.items()]

print('1. Alphabetical order with each students highest score.')

l3_highest_score_groups = [(key, max(values)) for key, valu



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有