两个清单
ListOne = ['steve','rob','jym','rich','bell','mick']
ListTwo = [('steve',22 ,178), ('rob', 23 ,189), ('jym', 25,165), ('steven',18 ,187), ('Manro',16 ,200), ('bell',21 ,167), ('mick', 24 ,180)]
我如何才能从 ListTwo 中为 ListOne 上的学生获取数据,例如two list intersections
。
输出如:
ListTwo = [('steve',22 ,178), ('rob', 23 ,189), ('jym', 25,165), ('bell',21 ,167), ('mick', 24 ,180)]
我试过这个,但我正在寻找更正式的东西:
for row in ListTwo:
if row[0] in ListOne :
print 'this student exist' + `row[0]`
else :
for i,e in enumerate(ListTwo):
#Check the student with the above results, will be removed
if row[0] == e:
temp=list(ListTwo[i])
pprint.pprint('I will remove this student : ' + `e`)
#Remove the Student
for f, tmp in enumerate(temp):
temp[f]= []
#pprint.pprint(temp)
ListTwo[i]=tuple(temp)