Hello, I am trying to define a function that allows me to look up a string inside a list of tuples, then return the corresponding tuple. The search should NOT be case sensitive either…
Here is an example, as well as the defined function that I tried:
test_scores = [('math','89','92','75'),
('English','89','100'),
('science','87','95','91'),
('history','99','93','95')]
def searchScores(searchString):
for i in range (len(test_scores)):
for j in range (len(test_scores[i])):
if test_scores[i][j].casefold()==searchString.casefold():
print(test_scores[i])
searchScores('89')
print("---------------")
searchScores('History')
print("---------------")
^Thats not really the best example, but I just wanted to show how there may be a different number of items within each.
The output SHOULD look like this:
('math','89','92','75')
('English','89','100')
-----------------------
('history','99','93','95')
But sadly it only returned the “—” print statements.
Could someone give me guidance on how to fix this problem? I am not very experienced in this area so I am just having a hard time putting the pieces together. Thanks in advance