It's a little embarrassing today
a=[' Xxxx_game.sql ', ' xxxx_game_sp.sql ', ' xxxx_gamelog_sp.sql ', ' xxxx_gamelog.sql ']for i in a: if ' gamelog ' in I: a.remove (i) Print a[' Xxxx_game.sql ', ' xxxx_game_sp.sql ', ' xxxx_gamelog.sql ']
The process of the calendar is obviously miss off the ' Xxxx_gamelog.sql ' this project, you can try it yourself, why will not be deleted, what is the reason?
We'll verify it again.
For I in a: if ' gamelog ' in I: print I, Xxxx_gamelog_sp.sql xxxx_gamelog.sql
Seeing the result, if we do not remove it, there is no problem. can be completely calendar.
So we probably know that when the remove operation on the list, the method of using the calendar is not possible. How to solve it?
a1=a[::] #这里我们镜像一个列表a1, but do not use a1=a, why, we can test a1=a[::] a1==a True; A1 is a False; A1=a a1==a true; Home can be tested, this is a feature of the list. For i in A1: if ' gamelog ' in I: a.remove (i) print a [' Xxxx_game.sql ', ' xxxx_game_sp.sql ']
One more example.
[{' Num ': ' 001 ', ' Name ': ' Zhang San ', ' workingtime ': ' Monday ', ' money ': ' 100 '}
{' Num ': ' 002 ', ' Name ': ' John Doe ', ' workingtime ': ' Tuesday ', ' money ': ' 200 '}]
Because there is ' Zhang San ', so delete {' Num ': ' 001 ', ' Name ': ' Zhang San ', ' workingtime ': ' Monday ', ' money ': ' 100 '} entire line, how to operate
The idea is to find the index of the element to delete in the list, and then call the pop, index as the parameter. The pop returns the element that was deleted. The rest of the queue is the remaining after the index element is deleted.
LName = [{' num ': ' 001 ', ' name ': ' Zhang San ', ' workingtime ': ' Monday ', ' money ': ' + '} {' num ': ' 002 ', ' name ': ' John Doe ', ' Workingti ' Me ': ' Tuesday ', ' money ': ' $ '}]for x in range (len (lname)): #列表遍历 if l[x][' name '] = = U ' Zhang San ': lname.pop (x)
#用 pop. break #操作完成 and break out
All right, let's get here today.