larken

勤奋的人生才有价值

导航

python code(1)

 1 from collections import UserList
 2 class MthChianList(UserList):
 3     def filter(self,predicste):
 4         return MthChianList(elem for elem in self if predicste(elem))
 5     def map(self,mapper):
 6         return MthChianList(mapper(elem) for elem in self)
 7     def for_each(self,action):
 8         for elem in self:
 9             action(elem)
10 lt=MthChianList(['A','B','c','d','e','F'])
11 lt.filter(str.islower).map(str.upper).for_each(print)

 

posted on 2019-03-23 19:29  larken  阅读(157)  评论(0编辑  收藏  举报