Firstly, I am very very new to Python. I understand the basics of for loops
used to iterate through a list, however, I am trying to replace an element
that passes a basic equality check, which is this case== " "
. When the
iteration reaches a " "
, it should replace the blank spot with a letter "A"
and return a True
.
However, this is not the case, it always returns a False
:(
If someone could find the time to point a very basic way to do this, it
would be much appreciated. I have searched, but most of the answers include
such things as enumerate
and len
functions etc, which is above my
understanding thus far. Thank you for any assistance offered.
# my list to iterate through.
myList = ["A", "A", " ", "B", "B", "C", " ", "A", "B"]
# my function to check for conditionals
def checkBook(spots,grade):
if spots[0] == grade and spots[1] == grade and spots[2] == grade:
return True
else:
return False
# my function to iterate through myList, then calls up the checkBook
# function to get a return
def compareElements():
for elements in myList:
if elements == " ":
elements = "A"
print (checkBook(myList, "A"))
compareElements()