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

javascript - Create websocket without connecting -

how to do line continuation in perl debugger for entering raw multi-line text (EOT)? -

android - Linear layout children not scrolling -