Hi can someone please explain to me why this function isn't working as I intended it to? I know I can do it by using the index of the list to check if the element is equal to a variable but why can't this method work?
Expectations- I wanted this function to change the element in list (stored
) if it matches a particular value. IE chance letter c
to the #
symbol in this example.
Results - The list (stored
) that is printed will have no difference and end up print [a,b,c,d,e]
Code
stored = ["a", "b", "c", "d", "e"]
def if_match():
for letters in stored:
if letters == "c":
letters = "#"
print stored