Skip to content Skip to sidebar Skip to footer

How To Subtract A Value In The Dictionary

The generation of dictionary from the function is below: The function will execute the mysql query output = {} def s(a,b,c): output = {a:[b,c]} return output a,b,c are

Solution 1:

Suppose your dictionary is called test_dict.

This will give you desired result.

from functools import reduce
result = reduce(lambda x,y: x-y, [int(i[1]) for i in test_dict.values()])

Solution 2:

You should give more info when asking questions. As the comments suggest, do take a look at how to ask better questions next time.

As for you question, you should store your dictionaries in a variable otherwise you can't access them later one. Store them as variables first:

a = {'a':['test','10']}
b = {'b':['test','5']}

Then grab the numbers
num_a = a["a"][1] --> outputs "10"
num_b = b["b"][1] --> outputs "5"# convert to int and subtractint(num_a) - int(num_b)

Post a Comment for "How To Subtract A Value In The Dictionary"