Learn how to use sets in code with Python 3. Discover how to make finite and infinite sets and why you might use one over the other. Discover how other languages provide set functionality.
- [Instructor] Now how do these work in code?…We can jump into Python 3 and see them in action.…Let's say we wanted to keep track…of the primary colors, red, blue and yellow.…To create a set, we can just write primaryColors…as the variable name for our set…and then write set, red, blue and yellow.…Then we get asked the question is green a primary color…or rather in the set of primary colors.…
To do this, we'll write color=green.…So any given color of choice, but we can put green in there.…And we can say if color.lower so this…is basically going to make our color lowercase…so we can match it to the set properly.…In primaryColors, so if this item is in primaryColors…then we can go ahead and print out that…it is a primary color by saying is a primary color.…And then otherwise, if it's not a primary color…then we can say is not a primary color.…
So here we are testing membership.…Is green in the set of primaryColors,…the set that does not have duplicates.…We go ahead and hit enter here.…We see that it is not red, blue or yellow,…
- Data types: Booleans, numbers, strings, and more
- Multidimensional arrays
- Jagged arrays
- Search and sort arrays
- Linked lists
- Stacks and queues
- Hash functions and hash tables
- Trees and graphs
Skill Level Intermediate
Understand data structures1m 25s
1. Introduction to Data Structures
4. Stacks and Queues
5. Hash-Based Data Structures
6. Trees and Graphs
- 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.