How to remove vowel out of the text argument


so if i cant do it with “pop” function, how to delete the vowels out of my argument

i wouldn’t delete vowels, using things like remove and pop are complicated solution.

.pop() is a method for list, text is a string

1 Like

Strings can’t be changed.

Can’t remove.
Can’t add.

That’s a good thing because it allows them to be used as keys in dictionaries.

What you can do is to use an intermediary data structure that supports the operations you want.

Removing is a rather strange thing to do here, because why then add them in the first place?

So you’d want a data structure that lets you add from nothing. List fits this requirement. After you’re done, create a string from your list with ''.join. Getting individual characters can be done by iterating over the string with a loop just like you do with your vowels.

If you were to go with deletions, then a list would be a bad fit because removing from a list other than at the end is a really expensive thing to do (can’t have holes, gotta move everything that follows)

The way I would think about this problem is that I’m making a new string which lacks some characters. I can therefore look at each letter, decide whether to keep it or not. The letters I keep can be stored somewhere. When I’ve looked at all letters I’d need to create a string from the characters I kept.

Another common pattern is to filter out what’s not wanted, and then join the result. The filter would be (not vowel), and then ''.join
The concept of that should sound ridiculously self-evident and obvious. Writing it is probably not obvious, that’s fine, don’t worry about it.

It’s not completely valid python because I would completely give it away. But it looks roughly like so:

''.join(filter not_vowel input_string)

filter is a built-in function, not_vowel is a function that returns a boolean, you’d have to define that yourself.

1 Like