Ignore numbers

Yesterday I wrote the following to ignore numbers inside text. This code does not ignore 123ab but ignores 123.34.

def ignoreNum(word):
  try:
    float(word)
    return("")
  except ValueError:
    return(word)

def main():
  myString = raw_input("Give string with some numbers in it:")
  print(" ".join([ignoreNum(x) for x in myString.split()]))

main()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s