Tuples: data that does not change
A tuple is an ordered sequence of values, like a list, but with a key difference: once created it cannot be modified . It is the…
Discover Python tuples and sets, two data structures that complement lists. You will learn how to group values that must not change, how to unpack them, how to remove duplicates and how to compare collections with set operations such as union, intersection and difference. Reinforce what you learn with practical exercises and learn to choose the right structure for each problem.
A tuple is an ordered sequence of values, like a list, but with a key difference: once created it cannot be modified . It is the…
A set is a collection of unique, unordered values. If you add the same value twice, only one is kept. It is the perfect structure…
Python sets work like sets in mathematics: you can join them, intersect them or subtract them. It is the shortest and most…
Python has three basic collections to store several values: list, tuple and set. Choosing the right one makes the code clearer…
Tuples shine when combined with unpacking : spreading the elements of a sequence into variables in a single line.
Create a Python program that stores the coordinates of a point in a tuple and unpacks them to show them.
Create a Python program with a function that returns the minimum and the maximum of a list of numbers at once.
Create a Python program that removes the repeated values from a series of numbers using a set.
Create a Python program that shows the numbers that appear in two lists at once, using the intersection of sets.
Create a Python program that counts how many different letters a text has.
Create a Python program that checks whether two words are made of the same distinct letters, regardless of the order or how many…
Create a Python program that compares the guest lists of two parties using set operations.
Create a Python program that sorts some students by grade using a list of tuples.
A named tuple ( namedtuple ) is a tuple whose fields have names: you access them with p.x instead of p[0] , and it is still…
Sets cannot be used as dictionary keys, but frozenset (immutable sets) can. They serve to group by “which letters appear”…
Extended unpacking first, *middle, last = data gathers all the leftover elements in a list. It is the most readable way to…