This commit is contained in:
yumoqing 2020-04-20 20:36:25 +08:00
parent 1969e95b75
commit f442a9873e

View File

@ -2,12 +2,22 @@
from appPublic.dictObject import DictObject
def keyMapping(dic,mappingtab,keepmiss=True):
"""
keyMapping mappingtab
{
"a1":"b1",
"a2":'b2",
...
}
"an" is key in dic
"bn" is key in result dictionary
"""
ret = {}
keys = [ k for k in dic.keys()]
if not keepmiss:
keys = [ k for k in dic.keys() if k in mappingtab.keys() ]
[ ret.update({mappingtab.get(k,k):dic[k]}) for k in keys ]
return DictObject(**ret)
return ret
def valueMapping(dic,mappingtab):
@ -37,4 +47,4 @@ def valueMapping(dic,mappingtab):
ret[k] = v
return DictObject(**ret)