From the course: Programming Foundations: Real-World Examples
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Sort sets - Python Tutorial
From the course: Programming Foundations: Real-World Examples
Sort sets
- Now that I've combined all of my friends into one massive set, I need to start narrowing down who I'm going to invite over for the game night. A good place to start narrowing down my set would be to determine who actually lives nearby. And since I'm making these plans kind of last-minute, I should remove all of my friends who live in far away zip codes. Here's the set representing all of the people with the same zip code as me, meaning they live nearby. If I overlay the set of all my friends, you can see that some of my friends have the same zip code as me, and others don't. So they must live far away. To get the set of just my local friends, I can use the intersection operation, which will return a set of items which exist in both the local set, and the set of all my friends. That cut out quite a few friends, but we've still got a ways to go. Settlers of Catan is only a four-player game, so I'll need to whittle down this to just three other people to invite over to play with me. I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.