def upper_consonant_y(w):
 a = []
 p = None
 for ch in w:
  if ((ch == 'y') and ((p is None) or (p in VOWELS))):
   a.append('Y')
  else:
   a.append(ch)
  p = ch
 return ''.join(a)

def upper_consonant_y ( w ) : a = [ ] p = None for ch in w : if ( ( ch == 'y' ) and ( ( p is None ) or ( p in VOWELS ) ) ) : a . append ( 'Y' ) else : a . append ( ch ) p = ch return '' . join ( a )
sets the initial y .