[Tutor] Remove a number from a string

Byron byron at christianfreebies.com
Tue Aug 23 22:03:11 CEST 2005


Shitiz Bansal wrote:

> Hi,
> Suppose i have a string '347 liverpool street'.
> I want to remove all the numbers coming at the starting of the string.
> I can think of a few ways but whats the cleanest way to do it?
>  
> Shitiz


Here's a function that can do what you're wanting to accomplish:

Byron
---

def removeNums(addr):
    text = addr.split()
    revisedAddr = ""
    for item in text:
        try:
            i = int(item)
        except:
            revisedAddr += item + " "
    return revisedAddr.strip()

# Test the function...  ;-)
address = "5291 E. 24rd Ave."
print removeNums(address)






More information about the Tutor mailing list