There is an ordered date list A['2016-01-01','2016-01-02','2016-01-03',....'2017-06-01']
And an unordered list of dates that need to be excluded B['2016-03-02','2016-03-08',]
I hope to put A Remove all B elements contained in . Is there anything wrong with the following writing?
for x in B:
A.remove(x)
It depends on your needs. There is nothing wrong with it and there is not a lot of data. I will provide you with a solution
This way of writing will report an error. If x is not in A, an error will be reported. This way of writing can first add an if to determine whether x is in A and then execute A.remove(x)
Try this simple way of writing:
from collections import OrderedDict
A = ['2016-01-01','2016-01-02','2016-01-03','2017-06-01','2016-03-08']
B = ['2016-03-02','2016-03-08']
d_set = OrderedDict.fromkeys(A)
for x in B:
A = d_set.keys()