May-01-2021, 05:55 PM
Hello,
I am trying to shorten large strings by applying some rules to it but not being able to figure it out.
Here is the code I have tried so far w/o success.
The string in endString is my end goal using the startString sample.
The rules are added as comments below.
Thank you in advance for your help
I am trying to shorten large strings by applying some rules to it but not being able to figure it out.
Here is the code I have tried so far w/o success.
The string in endString is my end goal using the startString sample.
The rules are added as comments below.
Thank you in advance for your help
startString = "Masonry - Concrete Block (Small) - Misc Air Layer - Insulation - Aluminium" endString = "Msnr-CncrBlck(Smll)-MiscAirLyr-Insltn-Almnm" #rules #words => 4 chars are left untouched #words > 4 chars have all lowercase vowels removed #special chars are kept, such as parenthesis and hyphens words = startString.split() for index in range(len(words)): if len(words[index]) > 4: vowels = ('a', 'e', 'i', 'o', 'u') for x in words[index]: if x in vowels: shorter = words[index].replace(x, "") endStringByCode = "".join(shorter) print (endStringByCode)