Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 23105

Python Morsels: Practical uses of sets

$
0
0

Sets are unordered collections of values that are great for removing duplicates, quick containment checks, and set operations.

What are sets?

Like lists, sets are collections of values:

>>> fruits={"apples","strawberries","pears","apples"}

But unlike lists, sets can't contain duplicate values:

>>> fruits{'apples', 'pears', 'strawberries'}

And sets are also unordered, meaning the values within a set may move around as new items are added to the set:

>>> fruits.add("limes")>>> fruits{'apples', 'pears', 'lime', 'strawberries'}

Sets are like dictionaries without values

Have you ever found yourself …

Read the full article: https://www.pythonmorsels.com/practical-uses-of-sets/


Viewing all articles
Browse latest Browse all 23105

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>