A set is a collection where every entry is unique. There cannot be any duplicate entries in a set. They are useful for finding unique elements, intersections, and other analytics.
- [Instructor] Python has a datatype for sets.…A set is like a list that does not allow duplicate elements.…Here in Komodo I've opened a working copy of sets.py…from chapter eight of the exercise files.…And you'll notice down here on line five and six…I've defined two different sets and I've defined them…just using strings and when I run this you'll notice…using my print_set function below…that what I get is an unordered list of…the unique characters in each string.…
There's no duplicates because a set…does not allow duplicates.…And the lists are unordered, each time I run it…you'll notice they come up in a different order.…Of course it's entirely possible to sort them.…If you really want them in order and now you see that…they are both sorted and each time I run it…they come up in the same sorted order.…But mostly if you're using sets,…you're going to be checking the membership of the set…and using them as sets not as lists.…
If you want an ordered list, you'll use a list or a string.…So for example, I can check for the members…
- Python anatomy
- Types and values
- Conditionals and operators
- Building loops
- Defining functions
- Python data structures: lists, tuples, sets, and more
- Creating classes
- Handling exceptions
- Working with strings
- File input/output (I/O)
- Creating modules
- Integrating a database with Python db-api
Skill Level Intermediate
Python: Programming Efficientlywith Michele Vallisneri2h 15m Intermediate
2. Language Overview
3. Types and Values
8. Structured Data
11. String Objects
12. File I/O
13. Built-in Functions
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.