Here is what I want to do but doesn\'t work:
mystring = \"hello world\"
toUpper = [\'a\', \'e\', \'i\', \'o\', \'u\', \'y\']
array = list(mystring)
for c in arr
You are not making changes to the original list. You are making changes only to the loop variable c
. As a workaround you can try using enumerate.
mystring = "hello world"
toUpper = ['a', 'e', 'i', 'o', 'u', 'y']
array = list(mystring)
for i,c in enumerate(array):
if c in toUpper:
array[i] = c.upper()
print(array)
Output
['h', 'E', 'l', 'l', 'O', ' ', 'w', 'O', 'r', 'l', 'd']
Note: If you want hEllO wOrld
as the answer, you might as well use join
as in ''.join(array)