close

[Solved] Type: list indices must be integers, not dict

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Type: list indices must be integers, not dict in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Type: list indices must be integers, not dict Error Occurs?

Today I get the following error Type: list indices must be integers, not dict in python.

How To Solve Type: list indices must be integers, not dict Error ?

  1. How To Solve Type: list indices must be integers, not dict Error ?

    To Solve Type: list indices must be integers, not dict Error You are looping over the values in the list referenced by data['execution']not indices.

  2. Type: list indices must be integers, not dict

    To Solve Type: list indices must be integers, not dict Error You are looping over the values in the list referenced by data['execution']not indices.

Solution 1

You are looping over the values in the list referenced by data['execution']not indices.

Just use those values (dictionaries) directly:

for i in data['execution']:
    cmd = i['test_case']['scriptname']

You probably want to give that a more meaningful loop name:

for entry in data['execution']:
    cmd = entry['test_case']['scriptname']

Solution 2

  • you can try this, it works for me
dataArray=data['execution']
for i in range(len(dataArray)):
    cmd = dataArray[i]['test_case']['scriptname']
  • This exactly loops by indices, so there will not be any confusion,
  • For me this is very simple and understandable

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read