Deleting specific characters from a string
John Hunter
jdhunter at ace.bsd.uchicago.edu
Wed Jul 9 18:17:46 EDT 2003
>>>>> "Behrang" == Behrang Dadsetan <ben at dadsetan.com> writes:
Behrang> is going to finally be what I am going to use. I not
Behrang> feel lambdas are so readable, unless one has serious
Behrang> experience in using them and python in general. I feel it
Behrang> is acceptable to add a named method that documents with
Behrang> its name what it is doing there.
If you want to go the functional programing route, you can generalize
your function somewhat using a callable class:
class remove_char:
def __init__(self,remove):
self.remove = dict([ (c,1) for c in remove])
def __call__(self,c):
return not self.remove.has_key(c)
print filter(remove_char('on'), 'John Hunter')
Cheers,
Jh Huter
More information about the Python-list
mailing list