"""假设开设了一门课程,并决定在期末的考试成绩中去掉最高分和最低分,
只对中间剩下的成绩做平均统计"""
from functools import reduce
def drop_first_last(grade):
grade.sort()
first,*middle,last = grade
a = reduce(lambda i,j:i+j,middle) # lambda表达式做法
# sum = 0
# for i in middle:
# sum += i
# print(sum/len(middle))
print(a/len(middle))
drop_first_last([90,100,60,88,92])
# 拆分操作的应用,可用*_表示不需要的变量
line = "chichung:*:-2:-2:Unprivileged User:/var/empty:/usr/bin"
uname,*_,homedir,sh = line.split(":")
print("\n")
print(uname)
print(homedir)
print(sh)
原文:https://www.cnblogs.com/chichung/p/9481589.html