# coding=utf-8
# 1.用lambda和filter完成下面功能:输出一个列表,列表里面包括:1-100内的所有偶数。(提示:可以用filter,lambda)
even = filter(lambda k: k % 2 == 0, range(1, 100))
assert even == range(2, 100, 2)
"""
2 用位置匹配,关键字匹配,收集匹配(元组收集,字典收集)分别写4个函数,完成功能;
传递3个列表参数:
[1,2,3],[1,5,65],[33,445,22]
返回这3个列表中元素最大的那个,结果是:445
"""
def func1(list1, list2, list3):
return max(max(list1), max(list2), max(list3))
assert func1([1, 2, 3], [33, 445, 22], [1, 5, 65]) == 445
def func2(k1=[], k2=[], k3=[]):
return max(max(k1), max(k2), max(k3))
assert func2(k1=[1, 2, 3], k2=[33, 445, 22], k3=[1, 5, 65]) == 445
def func3(*kargs):
max_list = []
for i in kargs:
max_list.append(max(i))
return max(max_list)
assert func3([1, 2, 3], [33, 445, 22], [1, 5, 65]) == 445
def func4(**kwargs):
max_list = []
for v in kwargs.values():
max_list.append(max(v))
return max(max_list)
assert func4(k1=[1, 2, 3], k2=[33, 445, 22], k3=[1, 5, 65]) == 445
Python函数第四节
最新推荐文章于 2018-12-11 09:12:40 发布