Python Set Union
- The union() method returns a new set with distinct elements from each and every one of the sets.
- The union of two or more sets is the set of all distinct elements shown in all the sets.
Learn python – python tutorial – python set union – python examples – python programs
Example:
-
- A = {1, 2}
- B = {2, 3, 4}
- C = {5}
Then,
- A∪B = B∪A ={1, 2, 3, 4}
- A∪C = C∪A ={1, 2, 5}
- B∪C = C∪B ={2, 3, 4, 5}
- A∪B∪C = {1, 2, 3, 4, 5}