python - How do I add 2 types of sets? -
for example
a = set() b = set() a.add(10) b.add(5) = + b #(this error)
the goal want = {5,10}. there simple way?
adding 2 sets same getting union of a
, b
:
>>> = set() >>> b = set() >>> a.add(10) >>> b.add(5) >>> a.union(b) set([10, 5])
remember sets don't have duplicate items, union of {5, 10}
, {5}
result in {5, 10}
.
another way can syntax-wise using pipe operator:
>>> a|b set([10, 5])
Comments
Post a Comment