'string'.strip(chars)-like function that removes from the middle?

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Tue Jun 17 20:34:59 CEST 2008

Peter Otten schreef:
> Ethan Furman wrote:
>> The strip() method of strings works from both ends towards the middle.
>> Is there a simple, built-in way to remove several characters from a
>> string no matter their location? (besides .replace() ;)
>>>> identity = "".join(map(chr, range(256)))


identity = string.maketrans('', '')

>>>> 'www.example.com'.translate(identity, 'cmowz.')
> 'exaple'

The saddest aspect of life right now is that science gathers knowledge
faster than society gathers wisdom.
   -- Isaac Asimov

Roel Schroeven

More information about the Python-list mailing list