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

Peter Otten __peter__ at web.de
Mon Jun 16 13:09:52 EDT 2008


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)))
>>> 'www.example.com'.translate(identity, 'cmowz.')
'exaple'

Peter



More information about the Python-list mailing list