#!/usr/bin/env python # -*- coding:utf8 -*- ###########
#找出开头(或结尾)不含有ab的字符串并将其提取出来
##########
s = ['ab_iua','sh_ab','a_bak'] print() def filter_start(array): ret = [] for i in array: if not i.startswith('ab'): ret.append(i) return ret print(s) tmp = filter_start(s) print(tmp) ########### print() def filter_test(f,array): tmp = [] for i in array: if not f(i): ###*******### tmp.append(i) return tmp def sb_show(n): return n.endswith('ab') print(s) res = filter_test(sb_show,s) print(res) tmp = filter_test(lambda n:n.endswith("ab"),s) print(tmp) ############## print() ###filter函数 s = ['ab_iua','sh_ab','a_bak'] print(s) print(filter_test(lambda n:n.endswith("ab"),s)) print(list(filter_test(lambda n:n.endswith("ab"),s)))