Shell
·
發表于 4年以前
·
閱讀量:2598
此函數在通過一個函數過濾給定的序列,測試序列中的每個元素是否為真。
arr = [1, 2, 3, 4, 5]
arr = list(filter(lambda x : x%2 == 0, arr))
print (arr) # [2, 4]