如何访问python中字典的字典

eit6fx6z  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(465)
a=[{'1st innings': {'team': 'Islamabad United',
   'deliveries': [{0.1: {'non_striker': 'Sharjeel Khan',
      'bowler': 'Anwar Ali',
      'runs': {'extras': 0, 'total': 0, 'batsman': 0},
      'batsman': 'SR Watson'}},
    {0.2: {'non_striker': 'Sharjeel Khan',
      'bowler': 'Anwar Ali',
      'runs': {'extras': 0, 'total': 0, 'batsman': 0},
      'batsman': 'SR Watson'}},
    {0.3: {'non_striker': 'Sharjeel Khan',
      'bowler': 'Anwar Ali',
      'runs': {'extras': 0, 'total': 0, 'batsman': 0},
      'batsman': 'SR Watson'}},
    {0.4: {'non_striker': 'Sharjeel Khan',
      'bowler': 'Anwar Ali',
      'runs': {'extras': 0, 'total': 0, 'batsman': 0},
      'batsman': 'SR Watson'}},
    {0.5: {'non_striker': 'Sharjeel Khan',
      'bowler': 'Anwar Ali',
      'runs': {'extras': 0, 'total': 0, 'batsman': 0},
      'batsman': 'SR Watson'}},
    {0.6: {'non_striker': 'Sharjeel Khan',
      'bowler': 'Anwar Ali',
      'runs': {'extras': 0, 'total': 0, 'batsman': 0},
      'batsman': 'SR Watson'}}}]

如何访问这本词典的不同索引,即python中的“第一局”、“击球手”、“全场”等
当我尝试使用[“1st innings”]访问第一局时,我不断收到错误“typeerror:列表索引必须是整数或片,而不是str”

ctehm74n

ctehm74n1#

你有一个- list 属于 dicts . 所以你需要像

print(a[0]['1st innings'])

相关问题