-1
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'}}}]

How do i access different indices of this dictionary i.e '1st innings','batsman','total' etc in python

I keep getting the error "TypeError: list indices must be integers or slices, not str" when i try to access 1st innings using a["1st innings"]

1 Answers1

0

You have a - list of dicts. So you need to access like

print(a[0]['1st innings'])
t4kq
  • 754
  • 1
  • 5
  • 11