May-02-2021, 02:46 PM
(May-01-2021, 06:04 PM)supuflounder Wrote: Don't you mean "<= 4" in line 5?
The problem is that you are doing
So let's look at what happens
1shorter
=
words[index].replace(x, "")
Let words[index] be the string "I don't want any lower-case vowels".
The first time through the loop starting on line 15, your first match is the "o" in "don't". So shorter is set to
"I dn't want any lower-case vowels"
The next time there is a match it matches the a in want, so shorter is set to
"I don't wnt any lower-case vowels"
Do you see the problem?
What you want to do is always test shorter, not words[index]. Which is a bit tricky, because you have removed the letter, so you have to manage the range. I'm not going to write the code for your homework, but this is as much help as I will give.
Thank you for your explanation on what words[index] is doing. It makes sense to me now.
This is not for a homework. I am working on a script for using at work so shorten some element naming. Very new to Python so trying my best to learn as I go with new challenges.