I have a list in a list, and I am trying to delete the third number of each sublist, but every time I am getting an error TypeError: list indices must be integers or slices, not list
a = [[0.0, 0.0, 0.0], [0.19, 0.36, 0.0], [0.24, 0.42, 0.0], [0.16, 0.08, 0.0], [0.05, -0.57, 0.0] ]
Desired result:-
a_updated = [[0.0, 0.0], [0.19, 0.36], [0.24, 0.42], [0.16, 0.08], [0.05, -0.57] ]
In the second part of my code, I wanted to merge this sublist according to a dictionary shown below, for example, the first value of dictionary:- 1: [1, 2] shows the merging of 1st and 2nd values i.e. [0, 0, 0.19, 0.36].
I guess this part of my code is right!
dict_a = { {1: [1, 2], 2: [2, 4], 3: [3, 5], 4: [4, 5] }
my attempt:-
dict_a = { 1: [1, 2], 2: [2, 4], 3: [3, 5], 4: [4, 5]}
a = [[0.0, 0.0], [0.19, 0.36], [0.24, 0.42], [0.16, 0.08], [0.05, -0.57]]
# first part
for i in a:
for j in a[i]:
del j[2]
print(j)
#second part
a_list = []
list_of_index = []
for i in dict_a:
index= []
a_list.append(index)
for j in dict_a_updated[i]:
print(j-1)
index.extend(a_updated[j-1])
print('index',index)
Error output -
file "D:\python programming\random python files\4 may axial dis.py", line 18, in <module>
for j in X[i]:
TypeError: list indices must be integers or slices, not list