Python Cookbook学习记录 ch1_10_2013/10/23
2013-10-23 22:50
483 查看
1.10 过滤字符串中不属于指定集合的字符
这个函数的实现方法和上一节一样:"除去要保留的剩下的都是要删除的"
这个函数的实现方法和上一节一样:"除去要保留的剩下的都是要删除的"
>>> import string >>> allchars = string.maketrans('','') >>> def makefilter(keep): delchars = allchars.translate(allchars,keep) def thefilters(s): return s.translate(allchars,delchars) return thefilters >>> just_vowels = makefilter('aeiou') >>> just_vowels('hello world') 'eoo'
相关文章推荐
- Python Cookbook学习记录 ch1_9_2013/10/23
- Python Cookbook学习记录 ch1_8_2013/10/23
- Python Cookbook学习记录 ch1_17_2013/10/25
- Python Cookbook学习记录 ch1_19_2013/10/27
- Python Cookbook学习记录 ch1_2_2013/10/21
- Python Cookbook学习记录 ch1_12_2013/10/24
- Python Cookbook学习记录 ch1_5_2013/10/22
- Python Cookbook学习记录 ch1_6_2013/10/22
- Python Cookbook学习记录 ch1_3_2013/10/21
- Python Cookbook学习记录 ch1_7_2013/10/22
- Python Cookbook学习记录 ch1_13_2013/10/24
- Python Cookbook学习记录 ch1_1_2013/10/20
- Python Cookbook学习记录 ch1_14_2013/10/25
- Python Cookbook学习记录 ch3_10/11_2013/10/30
- Python Cookbook学习记录 ch1_4_2013/10/22
- Python Cookbook学习记录 ch1_15_2013/10/25
- Python Cookbook学习记录 ch6_1_2013/11/6
- Python Cookbook学习记录 ch2_3_2013/10/27
- Python Cookbook学习记录 ch2_4/5_2013/10/27
- Python Cookbook学习记录 ch3_3/4_2013/10/29