I see some discussion about how to handle the task of "delete items when looping a list", e.g., this post.
An answer in this link says:
You are not permitted to remove elements from the list while iterating over it using a for loop.
It seems I can do it without problem:
words = ['DROP', 'TABLE', 'table_name']
for ii, word in enumerate(words):
print(ii)
print(word)
if words[ii] == 'DROP' and words[ii + 1] == 'TABLE':
words[ii] = 'DROP TABLE'
del words[ii + 1]
print(words)
yields:
0
DROP
1
table_name
['DROP TABLE', 'table_name']
Has python changed the restriction and we can remove items when looping now? I'm using python 3.7.