Python dictionary Value Comparison function example, python example
This example describes the dictionary Value Comparison function implemented by Python. We will share this with you for your reference. The details are as follows:
# Coding = utf8import loggingimport osfrom Lib. DealCsv import extends tpropertydicfrom wxPython. _ wx import false ''' is used for json data comparison, including comparison of attributes and attribute values. ''' # Used to compare strings and list PATH = lambda p: OS. path. abspath (OS. path. join (OS. path. dirname (_ file _), p) logging. basicConfig (level = logging. DEBUG, format = '% (asctime) s % (filename) s [line: % (lineno) d] % (levelname) s % (message) s ', datefmt = '% a, % d % B % Y % H: % M: % s', filename = PATH ('.. /Log/judgeProps. log '), filemode = 'W') def CmpObj (reaResultl, effectresult): try: if len (reaResultl) = len (effectresult): if cmp (reaResultl, effectresult) = 0: return True else: return False except T Exception, e: print e # The parameter contains two: # containVar: Find the characters contained # stringVar: the string def containVarInString (containVar, stringVar) to be searched: try: if isinstance (stringVar, str): if containVar in stringVar: return True else: return False except T Exception, e: print edef CmpValue (propsDic, limit tdic): try: containSeparatorList = [val for var in limit tdic. values () if containVarInString ("|", var) for val in var. split ("|")] notContainSeparatorList = [var for var in Alibaba tdic. values () if not containVarInString ("|", var)] effectvaluelist = notContainSeparatorList + containSeparatorList FalseBool = list (set ([False for var in propsDic. values () if var not in between tvaluelist]) if len (FalseBool): return False else: return True else t Exception, e: print epropsDic = {'itemid': 'XX ', 'item': 'track', 'serviceid': 'pageview', 'srcsubmodule ': 'sound record', 'srcposition': 'XX', 'srcpage ': 'discover _ recommend', 'srcpageid': 'XX', 'srcmodule ': 'focus tue', 'srtle tle': 'focus tues', 'focusid ': 'focus image id'} ExpecDic = {'itemid': 'XX', 'item': 'track', 'serviceid': 'pageview', 'srcsubmodule ': 'soundbar ', 'srcposition': 'XX', 'srcpage':' _ | You Like It | subscribe ', 'srcpageid': 'XX', 'srcmodule ': 'focus tues', 'srtle tle': 'focus tues', 'focusid': 'focus tuesid'} if _ name __= = "_ main __": print "helper house Test Result:" if CmpValue (propsDic, ExpecDic): print "Equel" else: print "not equel"
Running result: