标签:回文 ges lang exp ons 方式 UNC func 一个
lambda 定义匿名函数
lambda arguments: expression
def cube(y):
return y*y*y
lambda_cube = lambda y: y*y*y
li = [5, 7, 22, 97, 54, 62, 77, 23, 73, 61]
final_list = list(filter(lambda x: (x%2 != 0) , li))
print(final_list)
ages = [13, 90, 17, 59, 21, 60, 5]
adults = list(filter(lambda age: age>18, ages))
print(adults)
def interSection(arr1,arr2):
result = list(filter(lambda x: x in arr1, arr2))
print ("Intersection : ",result)
if __name__ == "__main__":
arr1 = [1, 3, 4, 5, 7]
arr2 = [2, 3, 5, 6]
interSection(arr1,arr2)
my_list = ["geeks", "geeg", "keek", "practice", "aa"]
result = list(filter(lambda x: (x == "".join(reversed(x))), my_list))
print(result)
参数:
https://www.geeksforgeeks.org/python-lambda-anonymous-functions-filter-map-reduce/
标签:回文 ges lang exp ons 方式 UNC func 一个
原文地址:https://www.cnblogs.com/shix0909/p/15037559.html