There's got to be an easier way to do this
Chris Barker
chrishbarker at home.net
Thu Jul 5 17:04:43 EDT 2001
Ryan LeCompte wrote:
> Try this:
>
> Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
> Type "copyright", "credits" or "license" for more information.
> IDLE 0.8 -- press F1 for help
> >>>import string
> >>>f = string.maketrans('', '')
> >>>string.translate('hello99there', f, string.letters)
> '99'
This only gets rid of letter, not any other character:
>>> string.translate('hello9-9there', f, string.letters)
'9-9'
If I understood correctly, what the poster wanted was to remove
everything that isn't a number. this works, however:
>>> remove = f.replace("0123456789","")
>>> string.translate('hello9-9there', f, remove)
'99'
-Chris
--
Christopher Barker,
Ph.D.
ChrisHBarker at home.net --- --- ---
http://members.home.net/barkerlohmann ---@@ -----@@ -----@@
------@@@ ------@@@ ------@@@
Oil Spill Modeling ------ @ ------ @ ------ @
Water Resources Engineering ------- --------- --------
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------
More information about the Python-list
mailing list