def nameToLabel(mname):
 labelList = []
 word = ''
 lastWasUpper = False
 for letter in mname:
  if (letter.isupper() == lastWasUpper):
   word += letter
  elif lastWasUpper:
   if (len(word) == 1):
    word += letter
   else:
    lastWord = word[:(-1)]
    firstLetter = word[(-1)]
    labelList.append(lastWord)
    word = (firstLetter + letter)
  else:
   labelList.append(word)
   word = letter
  lastWasUpper = letter.isupper()
 if labelList:
  labelList[0] = labelList[0].capitalize()
 else:
  return mname.capitalize()
 labelList.append(word)
 return ' '.join(labelList)

def nameToLabel ( mname ) : labelList = [ ] word = '' lastWasUpper = False for letter in mname : if ( letter . isupper ( ) == lastWasUpper ) : word += letter elif lastWasUpper : if ( len ( word ) == 1 ) : word += letter else : lastWord = word [ : ( - 1 ) ] firstLetter = word [ ( - 1 ) ] labelList . append ( lastWord ) word = ( firstLetter + letter ) else : labelList . append ( word ) word = letter lastWasUpper = letter . isupper ( ) if labelList : labelList [ 0 ] = labelList [ 0 ] . capitalize ( ) else : return mname . capitalize ( ) labelList . append ( word ) return ' ' . join ( labelList )
convert a string like a variable name into a slightly more human-friendly string with spaces and capitalized letters .