Python Forum
remove vowels in word with conditional
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
remove vowels in word with conditional
#1
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

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)
Reply


Messages In This Thread
remove vowels in word with conditional - by ambrozote - May-01-2021, 05:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,520 Aug-12-2021, 04:25 PM
Last Post: palladium
  counting vowels in a string project_science 3 2,579 Dec-30-2020, 06:44 PM
Last Post: buran
  Counting vowels in a string (PyBite #106) Drone4four 4 2,272 Jul-07-2020, 05:29 AM
Last Post: theknowshares
  Python Speech recognition, word by word AceScottie 6 16,036 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  Remove a sentence if it contains a word. lokhtar 6 5,933 Feb-11-2020, 04:43 PM
Last Post: stullis
  Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup soothsayerpg 5 7,135 Oct-27-2019, 09:53 AM
Last Post: newbieAuggie2019
  print a word after specific word search evilcode1 8 4,869 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  difference between word: and word[:] in for loop zowhair 2 3,688 Mar-03-2018, 07:24 AM
Last Post: zowhair
  no vowels function alex_bgtv 6 5,064 Jan-01-2018, 08:48 PM
Last Post: alex_bgtv
  replace vowels niru 9 20,798 Sep-26-2017, 12:46 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020