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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -