【问题标题】:Fetching value in nested dictionary在嵌套字典中获取值
【发布时间】:2019-03-05 01:28:35
【问题描述】:

如何从 Python 中的以下字典结构中获取世界 'hello'

d = {
  'k1': [1, 2, 3, {
    'tricky': ['oh', 'man', 'inception', {
      'target': [1, 2, 3, 'hello']
    }]
  }]
}

【问题讨论】:

  • 至少你可以说用哪种语言??
  • 也许d['k1'][3]['tricky'][3]['target'][3] ?
  • 在python中我试图解决这个问题
  • 那么我上面的回答会帮助你。

标签: python dictionary nested


【解决方案1】:

d['k1'][3]['tricky'][3]['target'][3]

【讨论】:

    【解决方案2】:

    应该这样做:

    In [1]: d['k1'][3]['tricky'][3]['target'][3]
    Out[1]: 'hello'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-27
      • 1970-01-01
      • 1970-01-01
      • 2017-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多