Skip to content
Advertisement

find and update a value of a dictionary in list of dictionaries

How can I find the dictionary with value user7 then update it’s match_sum eg add 3 to the existing 4.

JavaScript

I have this, and am not sure if its the best practice to do it.

JavaScript

Advertisement

Answer

You can also use next():

JavaScript

prints:

JavaScript

Note that if default (second argument) is not specified while calling next(), it would raise StopIteration exception:

JavaScript

And here’s what would happen if default is specified:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement