#!/usr/bin/python3 import functools def normalizeAcronyms(inputStrInWords): # Step1: Add extra space to prevent concatenate with previous word inputStrInWords = list(map(lambda a: a+' ' if len(a) > 1 else a, inputStrInWords)) # Step2: Remove the underscore, eg: c_d_a, l_p_a, etc. inputStrInWords = list(map(lambda a: a.replace('_', '').upper() if '_' in a else a, inputStrInWords)) # Step3: Combine if the next word is a single letter. retStr = functools.reduce(lambda a, b: a+b.upper() if len(b)==1 else a + ' ' + b, inputStrInWords) # Step4: Uppercase the first letter in the sentence retStr = retStr[0].upper() + retStr[1:] # Step5: Clean the space as added in the step1. return retStr.replace(' ', ' ') if __name__ == '__main__': inputStrInWords = ['c', 'd', 'a', 'trustee', 'and', 'b', 'b'] normalizeAcronyms(inputStr)