You can create a simple lookup map and just loop through your data to find the replacements, something like:
def display_list(A, B):
data = [("01", "02", "03", "04", "05", "06", "07"),
("08", "09", "10", "11", "12", "13", "14"),
("15", "16", "17", "18", "19", "20", "21")]
lookup_map = {A: "A", B: "B"} # a simple lookup map for our search
return [tuple(lookup_map.get(int(e), e) for e in s) for s in data]
A = 7
B = 9
test_list = display_list(A, B)
# [('01', '02', '03', '04', '05', '06', 'A'),
# ('08', 'B', '10', '11', '12', '13', '14'),
# ('15', '16', '17', '18', '19', '20', '21')]
Or, if you really want to do it long way around with manual checks:
def display_list(A, B):
data = [("01", "02", "03", "04", "05", "06", "07"),
("08", "09", "10", "11", "12", "13", "14"),
("15", "16", "17", "18", "19", "20", "21")] # our source list
result = [] # create an empty result list
for sublist in data: # loop through our source list of tuples
tmp_result = [] # create a temporary storage list
for element in sublist: # loop through each of the tuples from the source list
value = int(element) # convert the element to integer for comparison
if value == A: # if the element's value is the same value as A
tmp_result.append("A") # add "A" to our temporary storage list
elif value == B: # else, if the element's value is the same value as B
tmp_result.append("B") # add "B" to our temporary storage list
else: # if no match
tmp_result.append(element) # just add the original element
result.append(tuple(tmp_result)) # convert the temp list to tuple, add to the result
return result # return the result
And finally, if you want to do an in-place replacement (instead of temporary lists) like you attempted in your question:
def display_list(A, B):
data = [("01", "02", "03", "04", "05", "06", "07"),
("08", "09", "10", "11", "12", "13", "14"),
("15", "16", "17", "18", "19", "20", "21")] # source list
for i, sublist in enumerate(data): # loop through our source list, including an index
sublist = list(sublist) # convert the tuples into lists for modification
for j, element in enumerate(sublist): # loop through the sublist, including an index
value = int(element) # convert the element to integer for comparison
if value == A: # if the element's value is the same value as A
sublist[j] = "A" # replace the current element with "A"
elif value == B: # else, if the element's value is the same value as B
sublist[j] = "B" # replace the current element with "B"
data[i] = tuple(sublist) # convert back to a tuple and update the current list
return data # return the modified source data