Python is one of the world’s most popular programming languages for good reason — it provides powerful built-in data types to handle common problems. The set datatype can be used for performant collections where uniqueness is required. Python sets are more performant than listswhen it comes to lookups but slightlyless performant when iterating over elements.

Quick Introduction to Python’s Set Datatype

Python sets provide several methods by which elements can be added, removed, or retrieved. The most straightforward(ish) method is the set.add() method. The official Python documentation describes sets in the following way (R):

“A set is an unordered collection with no duplicate elements. Basic uses include membership testing and eliminating duplicate entries. Set objects also support mathematical operations like union, intersection, difference, and symmetric difference.”

Some notable takeaways are no duplicate elements, membership testing, and fancy mathematical operations. Those are considered the defining characteristics of Python’s set datatype.

#programming #data-science #python3 #python

Using Python’s set.update() Method for Fun and Profit
1.95 GEEK