A nesting problem of for and if in python

the code is as follows:

s = ["adam", "xxx", "lisa"]

L = ["adam", "xxx", "lisa", "bart"]

for x in L:

print "this is ---%s" % x
if x in s:
    print x
    L.remove(x)


print L

the results are as follows:
this is-adam
adam
this is-lisa
lisa

["xxx"," bart"]
[Finished in 0.2s]

Why is" xxx" directly ignored?

Sep.10,2021

the program runs as follows

Loop 1 br x points to adam: in L
print this is-adam
print adam
removes the adam,x in L pointing to xxx in L
cycle is over, x continues to go down, pointing to lisa in L

Loop 2 lisa
print this is-lisa
print lisa
remove the lisa,x in L pointing to bart in L
cycle is over, x continues to go down, can't go down, the whole cycle ends


is not ignored, but the position has changed


Let's see if you can understand it ( python3 ):
s = ["adam", "xxx", "lisa"]
L = ["adam", "xxx", "lisa", "bart"]
for x in L[:]:
    print("this is ---%s" % x)
    if x in s:
        print(x)
        L.remove(x)
print(L)
output
this is ---adam
adam
this is ---xxx
xxx
this is ---lisa
lisa
this is ---bart
['bart']
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b363f7-4ec62.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b363f7-4ec62.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?