Finding elements not in a list

前端 未结 10 733
一向
一向 2020-11-27 13:29

So heres my code:

item = [0,1,2,3,4,5,6,7,8,9]
z = []  # list of integers

for item in z:
    if item not in z:
        print item

z<

10条回答
  •  一整个雨季
    2020-11-27 13:55

    No, z is undefined. item contains a list of integers.

    I think what you're trying to do is this:

    #z defined elsewhere
    item = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    
    for i in item:
      if i not in z: print i
    

    As has been stated in other answers, you may want to try using sets.

提交回复
热议问题