没有函数名的函数叫匿名函数
匿名函数一般不单独使用,而是与max(),min(),map(),sorted(),filter()等内置函数一起使用
# print((lambda x,y:x+y)(1,2))
salary_dict = {
'nick': 3000,
'jason': 100000,
'tank': 5000,
'sean': 2000
}
# map
# max_salary = max(salary_dict) # 按键取最大的值
# print(max_salary)
# def func(res):
# return salary_dict[res]
#
# max_salary = max(salary_dict,key=func)
# print(max_salary)
# def max(iterable, key=None):
# salary_dict_iter = iterable.__iter__()
# init_num = 0
# for salary in salary_dict_iter:
# func_res=key(salary)
# if func_res > init_num:
# init_num,func_res = func_res,init_num
# return init_num
# res = max(salary_dict,key=func)
# print(res)
# salary_max = max(salary_dict,key=lambda name:salary_dict[name])
# print(salary_max)
# min
# map
name_list = ['jason','tank','sean']
res = map(lambda name:f'{name} sdb',name_list)
print(res)
# filter
lis = ['jason dsb','tank dsb','sean dsb','demon']
res = filter(lambda x:not x.endswith('dsb'),lis)
print(list(res))