Trying to compare same keys values from two different dict, If second dict value is bigger than first dict value then output should show different keys values only.
Example:
first={'a': '1000', 'b': '2000', 'c': '3000'}
second={'a': '1000', 'b': '3000', 'c': '5000'}
new dict output should be {'b': '3000', 'c': '5000'}
how to do this comperison
Using a dict comprehension
Ex:
first={'a': '1000', 'b': '2000', 'c': '3000'}
second={'a': '1000', 'b': '3000', 'c': '5000'}
print(dict((k, second[k])for k in second if second[k] > first[k]))
Output:
{'c': '5000', 'b': '3000'}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.