What is the best way to fix the error given in the run? I also somewhat understand that a list cannot change while being iterated over, but it still seems a little abstract.
myList = ["A", "B", "C", "D", "E", "F", "G", ]
for i in range(len(myList)):
if i == 2:
del (myList[4])
print(i, myList[i])
--------------------------Run-------------------------------------------------
"C:\Python36\python.exe"
Traceback (most recent call last):
0 A
File "C:/Users/reading.py", line 10, in <module>
1 B
2 C
print(i, myList[i])
3 D
4 F
IndexError: list index out of range
5 G
Process finished with exit code 1