[Tutor] Messy - Very Messy string manipulation.

Alan Gauld alan.gauld at btinternet.com
Wed Oct 28 14:06:10 EDT 2015


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...

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list