It’s a bit hard to explain in a concise title what I’m asking, so here’s the explanation. I have a list of classes and these objects all contain their own set of data. The problem that I’m having is that I try to iterate over these objects and filter out data that is used in one of the objects that precedes the current one in the list. The code fragment looks like this:
objs = [list-of-objects]
used = set([])
for obj in objs:
used = used.union(obj.callSomeFunc(used))
That callSomeFunc member returns a set of data that it has that does not intersect with the current used set.
This code works, but I don’t really like it, and I can’t believe that there isn’t a better way to do this.
The only thing I would change is to use
set.update()instead ofset.union():You could use
reduce(), but I think this would harm readability.Edit: Here’s the code using
reduce():