def soundex(name, len=4):
 soundex_digits = '01230120022455012623010202'
 sndx = ''
 fc = ''
 for c in name.upper():
  if c.isalpha():
   if (not fc):
    fc = c
   d = soundex_digits[(ord(c) - ord('A'))]
   if ((not sndx) or (d != sndx[(-1)])):
    sndx += d
 sndx = (fc + sndx[1:])
 sndx = sndx.replace('0', '')
 return (sndx + (len * '0'))[:len]

def soundex ( name , len = 4 ) : soundex_digits = '01230120022455012623010202' sndx = '' fc = '' for c in name . upper ( ) : if c . isalpha ( ) : if ( not fc ) : fc = c d = soundex_digits [ ( ord ( c ) - ord ( 'A' ) ) ] if ( ( not sndx ) or ( d != sndx [ ( - 1 ) ] ) ) : sndx += d sndx = ( fc + sndx [ 1 : ] ) sndx = sndx . replace ( '0' , '' ) return ( sndx + ( len * '0' ) ) [ : len ]
soundex module conforming to odell-russell algorithm .