why does this only print out “hy lk worlds!” when it should "hy lk wrlds!’

def anti_vowel(text):
vowels = list([“a”,“e”,“i”,“o”,“u”])
text = list(text)
for char in vowels:
for let in text:
if char == let:
return ‘’.join(text)
print(anti_vowel(“Hey look words!”))


remove is a very difficult approach, given successive vowels are skipped due to index shift (list and strings can’t have empty indexes). Example of index shift:

l   o   o   k
0   1   2   3

if we remove the o of index one we get:

l   o   k
0   1   2

if this is done with a loop, like in your program, successive vowels are skipped due to this index shift as demonstrated above


thanks, funny thing is i do remember doing these before, im redoing them for practice, and trying different ways, really it would be easy to use reg exp, i do remember either reading or listening about the index shifts every time it loops though and matches the index changes.

what do you think about sets


Sets? As in hash maps? I don’t see it. But if you have a way of using sets to remove vowels (feels silly to even type that) I’d love to hear it
Anyway, the point is to push values around using lists, loops – and get them to end up where you want them.


sets sounds like a terrible idea, if we have consonants which we need twice, it won’t work


Haha I guess sets was a bad idea… Just fig u have a set with vowels and a
set with your statement if you do the diff between them and join the finaal
setwould it not work?? Thanks for the speedy reply


Sets are unordered and only hold distinct values (no duplicates) – both those properties are incompatible for text representation.
There’s also no gain, because you can already replace characters as fast as you can read them (can’t go faster than that)


Thanks, I was thinking there’s methods for intersection ,diff and union,
but why not the difference of the 2 sets whos elements are ==, in other
words it returns everything but the == elements in both sets.

I’m new bare with me, like no prior comp exp, got hurt at work and doing
something with my time, I do like it a lot, def would switch from being an
RN to comp sci if I could, wish I went to school for this instead, and I’m
confusing myself more by thinking about this,
I actually started thinking about comp sci BC I wanted to build country
wide med rec, program, that everybody uses, so there’s no overlap In care,
Dr shopping, and continuity of care
Thanks for the help ,


If your representation (set) can’t store your value, then it doesn’t matter what operations you can do on your representation, because your value isn’t there


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.