# _*_ coding:utf-8 _*_
# @Time :2020/1/7 0:27
# @Author :dery
# @File :lambda.py
# @Software :PyCharm
# 匿名函数:简化函数定义
# 格式:lambda 参数1, 参数2..:运算
#
#
# def func():
# print('aaa')
#
#
# def add(a, b):
# s = a + b
# return s
#
#
# f = add
#
# s = lambda a, b: a + b
# print(s) # s就是一个函数function
# result = s(1, 2)
# print(result)
# s1 = lambda x, y: x * y
# result = s1(2, 5)
# print(result)
#
# # 匿名函数作为参数
# def func(x,y,func):
# print(x,y)
# print(func)
# s = func(x,y)
# print(s)
#
# # 调用func
# func(1,2,lambda a,b:a+b)
# list1 = [3, 5, 8, 9, 0]
# m = max(list1)
# print('列表最大值:',m)
# list2 = [{'a': 10, 'b': 20}, {'a': 13, 'b': 20}, {'a': 9, 'b': 20}, {'a': 29, 'b': 20}]
# for i in list2:
# print(i, i['a'])
# m = max(list2, key=lambda s: s['a'])
# print(m)
# map
list1 = [3, 4, 5, 6, 6, 8, 9, 1]
# result = map(lambda x: x + 2, list1)
# print(list(result))
# 对列表中的元素进行加1操作
# result = map(lambda x: x if x % 2 == 0 else x + 1, list1)
# print(list(result))
# for index, i in enumerate(list1):
# if i % 2 != 0:
# list1[index] = i + 1
# print(list1)
# reduce():对列表中的元素进行加减乘除运算的函数
# from functools import reduce
#
# tuple1 = (3, 5, 7, 6, 8)
# result = reduce(lambda x, y: x + y, tuple1)
# print(result)
# tuple2 = (1,)
# result = reduce(lambda x, y: x + y, tuple2, 10)
# print(result)
# filter:
list1 = [12, 5, 89, 23, 39]
result = filter(lambda x: x > 10, list1)
print(list(result))
print(list1)