#
# def use_filer(l):
#
# # 过滤偶数
# rest = filter(lambda n: n % 2 != 0, l)
# return rest
#
# if __name__ == '__main__':
# l = [1,2,3,4,5,6,7,8,9,10,11]
# rest = use_filer(l)
# # [1, 3, 5, 7, 9, 11]
# print(list(rest))
#
#
#
# def pow_number(l):
# # 返回 数据的立方
# rest_list = []
# for x in l:
# rest_list.append(x * x * x)
# return rest_list
#
# def f(n):
# return n * n * n
#
# def pow_num_use_map(l):
# return map(f,l)
#
#
# def pow_num_use_lambda(l):
# return map(lambda n:n * n * n,l)
#
#
#
# if __name__ == '__main__':
# l = [1,2,3,4,5,6,7,8,9,10]
# rest = pow_number(l)
# # [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
# print (rest)
# print ('--------------------------')
# rest_map = pow_num_use_map(l)
# # [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
# print (list(rest_map))
# print ('--------------------------')
# rest_lambda = pow_num_use_lambda(l)
# # [1, 8, 27, 64, 125, 216, 343, 512, 729, 1000]
# print (list(rest_lambda))
# 求和
def get_sum(l):
rest = 0
for i in l:
rest += i
return rest
def get_sum_use_py(l):
return sum(l)
from functools import reduce
def f(m,n):
return m + n
def get_sum_use_reduce(l):
return reduce(f,l)
def get_sum_use_lamdad(l):
return reduce(lambda m , n : m + n,l)
if __name__ == '__main__':
l = [1,2,4,6,7,8,9]
rest = get_sum(l)
# 37
print (rest)
print('------------------')
rest_py = get_sum_use_py(l)
print (rest_py)
print('------------------')
rest_reduce = get_sum_use_reduce(l)
print (rest_reduce)
print('------------------')
rest_lamdad = get_sum_use_lamdad(l)
print (rest_lamdad)