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

Peter Otten __peter__ at web.de
Tue Jun 17 07:02:53 EDT 2008


Sion Arrowsmith wrote:

> In article <g37pur$k5o$00$1 at news.t-online.com>,
> Peter Otten  <__peter__ at web.de> wrote:
>>Terry Reedy wrote:
>>>  >>> 'abcde'.translate(str.maketrans('','','bcd'))
>>> 'ae'
>>You should mention that you are using Python 3.0 ;)
>>The 2.5 equivalent would be
>>
>>>>> u"abcde".translate(dict.fromkeys(map(ord, u"bcd")))
>>u'ae'
> 
> Only if you're using Unicode:

... which is what you do if you are using the str type in 3.0.
 
Peter



More information about the Python-list mailing list