I try to remove all characters in the database that are smaller than a chosen character i. The database is a list of lists of characters.
def project(database, i):
test = database.copy()
for idx,lists in enumerate(database.copy()):
for char in lists:
print(char)
if char <= i:
test[idx].remove(char)
return test
a = [['A','B','D'],['A','B','C','D']]
print(project(a, 'C'))
Output:
A D A C
[['B', 'D'], ['B', 'D']]
Somehow the code never checks for 'B' although it is in the list. The same code without the if condition + remove line (line 5-6) does the following:
Output:
A B D A B C D
['A', 'B', 'D'], ['A', 'B', 'C', 'D']]
Why does the printed character change although I do not change the iterated list?