Python dictionary Value Comparison function example, python example

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.