yakupme yakupme - 11 days ago 6
Python Question

difference of two sets (lists) in python

stb_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
passive_boxes_list = []
active_boxes_list = set(stb_list) - set(passive_boxes_list)
print active_boxes_list


I have got two lists. The number is going to be added into the
passive_boxes_list
dynamically (1-16).

How I can subtract
stb_list
from
passive_box_list
.

For example: if
passive_boxes_list = [1 , 2 , 3]
then
active_box_list
should be:

active_boxes_list = [4, 5,6, 7, 8, 9, 10, 11, 12, 13,14,15,16]

Answer

You can try this:

list = [1,2,3,4,5,6,7]
bleh=[1,2,3,10]
for x in bleh:
    if x in list:
        del list[list.index(x)]
print list
Comments