I think this may be related to set being mutable
.
Basically, I can remove an element from a set using set.discard(element)
. However, set.discard(element)
itself returns None
. But I'd like to get a copy of the updated set. For example, if I have a list of sets, how can I get an updated copy conveniently using list comprehension operations?
Sample code:
test = [{'', 'a'}, {'b', ''}]
print [x.discard('') for x in test]
print test
will return
[None, None]
[set(['a']), set(['b'])]