def replaceAcronyms(text):
 def parseDirections(text):
  words = {'N': 'north', 'S': 'south', 'E': 'east', 'W': 'west'}
  output = [words[w] for w in list(text)]
  return ' '.join(output)
 acronyms = re.findall('\\b([NESW]+)\\b', text)
 for w in acronyms:
  text = text.replace(w, parseDirections(w))
 text = re.sub('(\\b\\d+)F(\\b)', '\\g<1> Fahrenheit\\g<2>', text)
 text = re.sub('(\\b)mph(\\b)', '\\g<1>miles per hour\\g<2>', text)
 text = re.sub('(\\b)in\\.', '\\g<1>inches', text)
 return text

def replaceAcronyms ( text ) : def parseDirections ( text ) : words = { 'N' : 'north' , 'S' : 'south' , 'E' : 'east' , 'W' : 'west' } output = [ words [ w ] for w in list ( text ) ] return ' ' . join ( output ) acronyms = re . findall ( '\\b([NESW]+)\\b' , text ) for w in acronyms : text = text . replace ( w , parseDirections ( w ) ) text = re . sub ( '(\\b\\d+)F(\\b)' , '\\g<1> Fahrenheit\\g<2>' , text ) text = re . sub ( '(\\b)mph(\\b)' , '\\g<1>miles per hour\\g<2>' , text ) text = re . sub ( '(\\b)in\\.' , '\\g<1>inches' , text ) return text
replaces some commonly-used acronyms for an improved verbal weather report .