Python Lower Case Dict Values Before Comparing 2 Dicts Using Itemgetter
i compare 2 dicts dict1 keys and values must be in dict2 The problem is the in dict2 the values are in upper case and i like to lower case them before comparing them. if it possibl
Solution 1:
Try:
from operator import itemgetter
dict1 = {"version": "fff", "ff": 1, "name_app": ["for"]}
dict2 = {
"version": "FFF",
"ff": 1,
"name_app": ["for"],
"dir": "c",
"path": "cc",
}
g = itemgetter(*dict1)
if g(dict1) == tuple(
map(lambda x: x.lower() ifisinstance(x, str) else x, g(dict2))
):
print("True")
else:
print("False")
Prints:
True
Post a Comment for "Python Lower Case Dict Values Before Comparing 2 Dicts Using Itemgetter"