I’m attempting to find all vowels within a string to replace them.
Here is what I’ve been working with:
word = "abcde"
vowels = "aeiou"
v = list(vowels)
hey = False
for i in range(len(word)):
if word[i] == v:
hey = True
print hey
I was trying to replace all those positions with strings with the symbol “$”, but I can’t figure out how I can do this linear search properly.
Under the assumption that this is for an assignment/class of some sort, here is a simple example. You can iterate through a string by character, so this goes through each letter in your vowel set and replaces each instance in your word with the
$character:And keeping it simple, to do it in reverse:
This doesn’t get into a lot of other very cool functions which can handle this in one/two lines, but hopefully will serve as a building block 🙂