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

Sion Arrowsmith siona at chiark.greenend.org.uk
Tue Jun 17 12:02:19 CEST 2008

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")))

Only if you're using Unicode:

>>> 'abcde'.translate(string.maketrans('',''), 'bcd')
>>> sys.version_info
(2, 4, 4, 'final', 0)

\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list