7. Tuples and Sets in python

Опубликовано: 07 Октябрь 2024
на канале: Taylor Sparks
1,857
32

Tuples and Sets are a lot like Lists which we learned about in our last video. They both store multiple data. However, there are some big differences. Sets cannot have any duplicate values and a set is also unordered (no index). Tuples are like lists that cannot be changed (immutable). These both offer some advantages. We can take advantage of the fact that sets don't allow duplicates to remove duplicates from a list with ease by simply converting a list to a set. Sets also allow us to identify in Venn diagram fashion, the elements in common between sets or the differences, etc using union(), intersection(), difference(), and symmetric_difference() methods.
We do an example where we pull the keywords from the internet movie database for Fellowship of the Ring, Harry Potter (Sorcerer's stone), and Star Wars (A New Hope) and see what they have in common etc. Try it yourself with the .csv file available on my github.
https://github.com/sp8rks/MSE2001pyth...
Tuples make assignments simultaneously so we can use these to easily swap variable values. We can also take advantage of packing and unpacking with tuples.