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

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to