The following example seems to indicate that the integrity of "for" is questionable. Please note that 'c' is not in 'words', yet is not removed from list.
phrase = "Don't panic!"
plist = list(phrase)
words = 'on tap'
for char in plist:
# if the char from plist is not in words, then remove it from plist
if char not in words:
plist.remove(char)
else:
pass
print(plist)
['o', 'n', 't', ' ', 'p', 'a', 'n', 'c']
I understand what is happening - the initial state of 'for' sequence is not preserved: the iteration is not consistent.
Maybe it's me. However, same logic as implemented in tcl produces a result that reflects the intent of 'foreach' iteraction:
o n t ' ' p a n
Please advise on what I am missing about Python iteration. Rick