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

python – 以字典形式访问字典

5b51 2022/1/14 8:21:17 python 字数 1022 阅读 483 来源 www.jb51.cc/python

我有一个数据源,最好用字典建模(它是key = value对的集合).对于特定的可视化目的,我需要提供类似列表的数据访问接口(除了常规字典界面),这意味着您应该能够执行以下操作:data['mykey'] # returns the associated value data[12][0] # returns the 13th key in the dict

概述

data["mykey"] # returns the associated value
data[12][0] # returns the 13th key in the dictionary
data[12][1] # returns the 13th value in the dictionary

data[12] = ("mykey","myval")

data["mykey"] = "myval"

  def SetData(self,cols,data):
    for idx,row in enumerate(data):
      item = dict((k,v.rstrip() if hasattr(v,'rstrip') else v) for k,v in zip(cols,row))

      self.data[idx] = item

      self.byid[row[0]] = item

总结

以上是编程之家为你收集整理的python – 以字典形式访问字典全部内容,希望文章能够帮你解决python – 以字典形式访问字典所遇到的程序开发问题。


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

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

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


联系我
置顶