How to add two sets

a = {'a','b','c'} b = {'d','e','f'} 

I want to add above two given values.

A conclusion is required, for example,

 c = {'a','b','c','d','e','f'} 
+8
python set
source share
2 answers

This is not a dict , this is set . All you have to do to combine them is c = a|b .

Settings are unordered sequences of unique values. a|b is the union two sets (a new set with all the values โ€‹โ€‹found in any set). This is a class of operations called a โ€œset operationโ€ that sets up handy tools for.

+16
source share

You can use update () to combine set (b) into set (a) Try this.

 a = {'a', 'b', 'c'} b = {'d', 'e', 'f'} a.update(b) print a 

and second solution:

 c = a.copy() c.update(b) print c 
+8
source share

All Articles