I am an amateur Python user, so bear with me. I created a list, and filled it with hashes. But I am having trouble, because I need to search the entire list to find the first hash with a specific value and update it. Does anyone know how?
character = [{"No": 1, "Name":"Jeff", "Level": 29, "Health": 290},
{"No": 2, "Name":"Bill", "Level": 31, "Health": 310},
{"No": 3, "Name":"EMPTY", "Level": 0, "Health": 0},
{"No": 4, "Name":"EMPTY", "Level": 0, "Health": 0},
{"No": 5, "Name":"EMPTY", "Level": 0, "Health": 0},
{"No": 6, "Name":"EMPTY", "Level": 0, "Health": 0}]
In this code, I need to find the first instance of the empty name, and update its hash with another hash
I tried to use indexing, but it did not work, saying "Invalid Syntax"
x = character.index("EMPTY")
character[x].update(player)
print(character)
yea,list can't use index method directly。 should used linear search to catch 'Name' == 'Empty'。