筛选
movie_people = ['sb_alex','sb_wupeiqi','linhaifeng','sb_yuanhao']## ret = []# for p in movie_people:# if not p.startswith('sb'):# ret.append(p)# print(ret)def filter_test(array): ret = [] for p in array: if not p.startswith('sb'): ret.append(p) return retprint(filter_test(movie_people))
进阶版
movie_people = ['sb_1','sb_2','3','sb_4']def sb_show(n): return n.startswith('sb')def filter_test(func,array): ret = [] for p in array: if not func(p): ret.append(p) return retres = filter_test(sb_show,movie_people)print(res)
filter,后面传到前面。运算得出布尔值,为ture保留,false不保留。