Anti_vowel


#1

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:
text.remove(let)
return ‘’.join(text)
print(anti_vowel(“Hey look words!”))


#2

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


#3

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


#4

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.


#5

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


#6

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


#7

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)


#8

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 ,


#9

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


#10

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