li = [1, 2, 3, 4, 5, 6] def fun(item, num): if item == num: return 1 else: return 0 def fun1(item, num): if item>num: return 1 else: return 0 li1 = list(map(lambda x: fun(x, 3), li)) print(li1) li2 = list(map(lambda x: fun1(x, 3), li)) print(li2) li3 = list(map(lambda x: fun1(x, 4), li)) print(li3) li4 = list(map(lambda x: fun1(x, 5), li)) print(li4) l = [i+j+k+n for i, j, k, n in zip(li1, li2, li3, li4)] print(l) print() print('values:', li[l.index(max(l))], 'index:', l.index(max(l))) print('-'*100) li = ['python', 'c++', 'java', 'javascript', 'go'] import operator def filter_string(item, filter_s): if operator.contains(item, filter_s): return 1 else: return 0 l1 = list(map(lambda x: filter_string(x, 'p'), li)) print(l1) l2 = list(map(lambda x: filter_string(x, 'o'), li)) print(l2) l3 = list(map(lambda x: filter_string(x, 'a'), li)) print(l3) l4 = list(map(lambda x: filter_string(x, 'j'), li)) print(l4) l = [i+j+k+n for i,j,k,n in zip(l1, l2, l3, l4)] print(l) print() print('values:', li[l.index(max(l))], 'index:', l.index(max(l)))
标签:map,python,list,li,filter,过滤,print,列表,lambda From: https://www.cnblogs.com/moon3496694/p/17215942.html