[Tutor] Messy - Very Messy string manipulation.

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Oct 29 03:50:32 EDT 2015


On 28/10/2015 18:06, Alan Gauld wrote:
> On 28/10/15 17:35, Peter Otten wrote:
>> Alan Gauld wrote:
>>
>>> On 28/10/15 16:37, Peter Otten wrote:
>>>
>>>>>>> 'The cow moos louder than the frog'.translate(str.maketrans("", "",
>>>> "aeiouAEIOU"))
>>>> 'Th cw ms ldr thn th frg'
>>>
>>> Even easier, forget the maketrans stuff and just use
>>>
>>> 'The cow moos louder than the frog'.translate(None,'aeiouAEIOU')
>>
>> This only works for byte strings, not unicode.
>
> Aha, I tried it in Python 2.7 which worked, but I didn't
> think about v3...
>

Seems like as good a place as any to point out that in Python 3 all of 
the following also exist.

static bytes.maketrans(from, to)
bytes.translate(table[, delete])

static bytearray.maketrans(from, to)
bytearray.translate(table[, delete])

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list