def ExpandMacros(string, expansions):
 if ('$' in string):
  for (old, new) in expansions.iteritems():
   assert ('$(' not in new), new
   string = string.replace(old, new)
 return string

def ExpandMacros ( string , expansions ) : if ( '$' in string ) : for ( old , new ) in expansions . iteritems ( ) : assert ( '$(' not in new ) , new string = string . replace ( old , new ) return string
expand $ per expansions dict .