您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Python实现的字典值比较功能示例

5b51 2022/1/14 8:15:33 python 字数 4338 阅读 314 来源 www.jb51.cc/python

本文实例讲述了Python实现的字典值比较功能。分享给大家供大家参考,具体如下:

概述

本文实例讲述了Python实现的字典值比较功能分享给大家供大家参考,具体如下:

#coding=utf8
import logging
import os
from Lib.DealCsv import ExceptPropertyDic
from wxPython._wx import false
'''''
用于json数据的比较,包含属性属性值的比较。
'''
#用于比较字符串、列表
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,exceptResult):
  try:
    if len(reaResultl)==len(exceptResult):
      if cmp(reaResultl,exceptResult)==0:
        return True
      else:
        return False
    else:
      return False
  except Exception,e:
    print e
#参数包含两个:
#containVar:查找包含的字符
#stringVar:所要查找的字符串
def containVarInString(containVar,stringVar):
  try:
    if isinstance(stringVar,str):
      if containVar in stringVar:
        return True
      else:
        return False
    else:
      return False
  except Exception,e:
    print e
def CmpValue(propsDic,exceptDic):
  try:
    containSeparatorList=[val for var in exceptDic.values() if containVarInString("|",var) for val in var.split("|")]
    notContainSeparatorList=[var for var in exceptDic.values() if not containVarInString("|",var)]
    exceptValueList=notContainSeparatorList+containSeparatorList
    FalseBool=list(set([False for var in propsDic.values() if var not in exceptValueList ]))
    if len(FalseBool):
      return False
    else:
      return True
  except Exception,e:
    print e
propsDic={
  'itemId ': 'XX','item' : 'track','serviceId' : 'pageview','srcSubModule' : '声音条','srcPosition' : 'XX','srcPage' : '发现_推荐','srcPageId' : 'XX','srcModule' : '焦点图','srcTitle' : '焦点图标题','focusId' : '焦点图ID'
  }
ExpecDic={
  'itemId ': 'XX','srcPage' : '发现_推荐|猜你喜欢|订阅','focusId' : '焦点图ID'
  }
if __name__=="__main__":
  print "编程小技巧测试结果:"
  if CmpValue(propsDic,ExpecDic):
    print "Equel"
  else:
    print "not equel"

运行结果:

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python字典操作技巧汇总》、《Python数据结构与算法教程》、《Python加密解密算法与技巧总结》、《Python编码操作技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程

希望本文所述对大家Python程序设计有所帮助。

总结

以上是编程之家为你收集整理的Python实现的字典值比较功能示例全部内容,希望文章能够帮你解决Python实现的字典值比较功能示例所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶