python - Deleting multiple objects within JSON -


name_list = [{'name': 'john'}, {'name': 'johan'}, {'name': 'john'}]      in xrange(len(name_list)):         if name_list[i]["name"] == "john":             del name_list[i] 

after first time recognizing john, deletes object breaks out of function. how can continue traversing till end , delete every single json object has john name?

many guys!

you shouldn't remove items form sequence iterating over. it's safer build new dictionary without elements don't want:

new_list = [d d in name_list if d['name'] != 'john'] 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -