Some simple problems solved by various string methods.

  1. How to compare strings but ignore punctuation?

  2. How long is the leading whitespace in a string?

  3. Make multiple spaces between words into just one space between words.

Combining Methods

One = "Here: is a string!"
Two = "Here is, a string?"
def nopunc(x):
  v = x.replace(':','').replace('!','')
  w = v.replace(',','').replace('?','')
  return w
print One == Two
print nopunc(One) == nopunc(Two)
Three = " some text"
leadspacesize = ( len(Three) -
                  len(Three.lstrip()) )
Four = "some text irregular space"
print ' '.join(Four.split())