from functools import reduce name = ['joe','susan','black','lilia'] age = [19,20,18,30] sex = ['m','w','w','m'] #案例一:格式化用户的英文名,要求首字母大小,其它字母小写 new_name = map(lambda x:x.title(),name) print(list(new_name)) #案例二:将用户英文名、年龄、性别三个集合的数据结合到一起,形成一个元祖列表 users = map(lambda x,y,z:(x,y,z),name,age,sex) new_users = list(users) print(new_users) #案例三:过滤性别为男的用户 m_users = filter(lambda x:x[2] =='m',new_users) new_m_user = list(m_users) print(new_m_user) #案例四:求性别为男的用户的平均年龄 sum_age = reduce(lambda x,y:x+y[1],new_m_user,0) print(sum_age/len(new_m_user))