I'm trying to manipulate a string.
After extracting all the vowels from a string, I want to replace all the 'v' with 'b' and all the 'b' with 'v' from the same string (i.g. "accveioub" would become ccvb first, then ccbv).
I'm having problem to swap the characters. I end up getting ccvv and I figured I'd get that based of this code. I'm thinking of iterating through the string and using an if statement basically staying if the character at index i .equals"v" then replace it with "b" and an else statement that says "b" replace it with "v" and then append or join the characters together?
Here's my code
def Problem4():
volString = {"a", "e", "i", "o", "u", "A", "E", "I", "O", "U"}
s = "accveioub"
chars = []
index = 0
#Removes all the vowels with the for loop
for i in s:
if i not in volString:
chars.append(i)
s2 = "".join(chars)
print(s2)
print(s2.replace("v", "b"))
print(s2.replace("b", "v"))
>>> Problem4()
ccvb
ccbb
ccvv
>>>