1.2 任意长度的可迭代对象分解为N个元素
程序员文章站
2022-05-28 13:10:16
...
解决方式:*表达式
grades = [56,45,26,89,35,98,54,39,54,80,54,62,61,60,97,95,90,61,37,65]
def drop_first_last(grades):
first,*middle,last = grades
return avg(middle)
def avg(grades):
return sum(grades)/len(grades)
print(drop_first_last(grades))
输出:
63.166666666666664
上一篇: 从零开始学Java之六——类与对象
下一篇: 从字典中提取子集