a = [["A","B"],["C","D"],["D","E"]]
for i in range(len(a)):
if i == 0:
a[i] = []
print(a) # [[], ['C', 'D'], ['D', 'E']]
I used above to remove inside list from a list but it prints [] . I want to remove the list itself.
Desired Output :- [['C', 'D'], ['D', 'E']]
Another approach which I tried as below works for i=0, i=1 and even i=2 But when my condition is all true ( kind of one case) then,
a = [["A","B"],["C","D"],["D","E"]]
for i in range(len(a)):
if True:
a.pop(i)
print(a) # IndexError: pop index out of range
I understood that using pop is shifting the indexes and causing the error as out of range. Need solution to tackle this.