collections: Counter and defaultdict
The collections module offers specialized data structures. The two most useful ones solve perfectly the counting and grouping…
Python ships with hundreds of ready-to-use modules. In this lesson you will meet the most useful ones: datetime to work with dates, collections with Counter and defaultdict, statistics to compute averages and medians, and itertools and string for common tasks. You will also learn to read the documentation to find what you need, with practical exercises.
The collections module offers specialized data structures. The two most useful ones solve perfectly the counting and grouping…
The statistics module calculates the most common statistical measures of a list of numbers. With Python's built-in functions (…
Two small modules that solve very specific tasks: itertools generates combinations of elements and string offers ready-made…
Nobody knows the standard library by heart. The most useful skill of a programmer is not remembering every function, but knowing…
Two small modules of the standard library solve problems that you would otherwise program by hand: keeping a list sorted and…
Three more standard library modules that save code and make programs clearer.
Create a Python program that calculates the due date of an invoice by adding some days to the issue date.
Create a Python program that shows the three words that are repeated the most in a text using Counter .
Create a Python program that groups cities by country using defaultdict .
Create a Python program that calculates the mean, the median and the standard deviation of a series of numbers with the…
Create a Python program that generates a random password with the random and string modules.
Create a Python program that shows all the distinct anagrams of a word using itertools.permutations .
The bisect module finds positions in sorted lists using binary search. It is ideal for turning a number into a category according…
The heapq module implements heaps (priority queues). With nlargest and nsmallest you get the extremes of a list without sorting…
The @lru_cache decorator from the functools module stores the results of a function so they are not recalculated. It also lets…
operator.itemgetter creates a function that extracts one or several items from each record. It is the clean way to sort by…
The textwrap module formats paragraphs: it splits a text into lines of a maximum width and can shorten it by adding an ellipsis.