0
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]
4
  • Are you after some kind of view which updates each time passive_boxes_list dynamically updates? Commented Nov 21, 2016 at 15:06
  • 3
    Your code already works, doesn't it? (Although you could potentially convert active_boxes_list to a list from a set.) Can you be more specific about what behaviour you want? If you want something that really updates dynamically, you're going to have to build a function or a class. (Also, I think the name operation is just "difference", not "distraction", in English) Commented Nov 21, 2016 at 15:25
  • One possibility that is about as terse as any other that doesn't involve a non-pythonic amount of reliance on globals or other magic: active_boxes_list -= set(passive_boxes_list) Commented Nov 21, 2016 at 15:39
  • perhaps this is better as a class to encapsulate the moving of number between estates and so you can easily update both when a new active or passive is added Commented Nov 21, 2016 at 15:39

2 Answers 2

3

You should use the List Comprehension feature.
So you should have something like active_boxes_list = [x for x in stb_list if x not in passive_list]
Hope this help !

Sign up to request clarification or add additional context in comments.

1 Comment

The OP's set commands already do this part of the job (more elegantly)!
-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.