O
O
Oleg Andreev2020-07-08 22:42:39
Python
Oleg Andreev, 2020-07-08 22:42:39

List index out of range error, how to fix?

I can't figure out what's wrong. either the list overflows or the index does not exist. but everything is printed, so most likely the first. I hope someone understands. I won't upload all the code. If you need additions, I will be happy to provide.

test_test = dict()

        for i in range(len(self.resultDict['materials'])):
            print(self.resultDict['materials'][i]['material_id'], i)
            if self.resultDict['materials'][i]['material_id'] not in test_test:
                test_test[self.resultDict['materials'][i]['material_id']] = list()
            test_test[self.resultDict['materials'][i]['material_id']].append(i)

            if self.resultDict['materials'][i]['color_id'] not in test_test:
                print(self.resultDict['materials'][i]['color_id'], i)
                test_test[self.resultDict['materials'][i]['color_id']] = list()
            test_test[self.resultDict['materials'][i]['color_id']].append(i)
      
            if self.resultDict['materials'][i]['depth_id'] not in test_test:
                test_test[self.resultDict['materials'][i]['depth_id']] = list()
            test_test[self.resultDict['materials'][i]['depth_id']].append(i)

if you remove the last two if-a, then everything is done. crashes before converting to pdf.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question