Last active
June 9, 2022 03:13
-
-
Save vthily/e396dba8dfa0a1ab9cd1e9e66a5d85c5 to your computer and use it in GitHub Desktop.
Revisions
-
vthily revised this gist
May 18, 2022 . No changes.There are no files selected for viewing
-
vthily created this gist
May 6, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ #!/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)