posts - 183,  comments - 10,  trackbacks - 0
 1 class Filter:
 2     def init(self):
 3         self.blocked = []
 4     def filter(self, sequence):
 5         return [x for x in sequence if x not in self.blocked]
 6 
 7 class SPAMFilter(Filter): # SPAMFilter 是 Filter 的子类
 8     def init(self):
 9         self.blocked = ['SPAM']
10 
11 = Filter()
12 f.init()
13 print(f.filter([123]))
14 
15 = SPAMFilter()
16 s.init()
17 print(s.filter(['SPAM''SPAM''SPAM''SPAM''eggs''bacon''SPAM']))

输出:
>>>
[1, 2, 3]
['eggs', 'bacon']
posted on 2013-05-19 11:39 unixfy 阅读(328) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理