[Tutor] Problem Stripping

Mark Lawrence breamoreboy at yahoo.co.uk
Sat Mar 31 15:22:58 CEST 2012


On 31/03/2012 03:01, bob gailer wrote:
> Then, of course, there's "15:45".replace(':','')
>

For the record in earlier Python versions such as the one the OP is 
using you can do

 >>> allchars = "".join([chr(x) for x in range(256)])
 >>> 'www.example.com'.translate(allchars, 'cmowz.')
'exaple'

As of Python 2.6 you don't even need the allchars hence

 >>> 'www.example.com'.translate(None, 'cmowz.')
'exaple'

-- 
Cheers.

Mark Lawrence.



More information about the Tutor mailing list