Lists are used to store and manipulate an ordered collection of things.
Tuples are technically just immutable lists, but by convention we tend to use tuples and lists for quite different purposes.
In Python, slicing looks like indexing with colons (:). You can slice a list (or any sequence) to get the first few items, the last few items, or all items in reverse.
Sequences are iterables that have a length. Sequences are ordered collections (they maintain the order of their contents). The most common sequences built-in to Python are string, tuple, and list.
Python programmers typically check for empty lists by relying on truthiness.
When should you use the built-in list function in Python? And when shouldn't you?
Python's dictionaries act as lookup tables which map keys to their values.
Python code that uses indexes can often be refactored into more readable code that doesn't rely on indexing.
Have a nested list-of-lists in Python? What's the most idiomatic way to flatten it?
There's more than one way deduplicate an iterable in Python. Which approach you take will depend on whether you care about the order of your items.
Python's collections.Counter class is extremely handy, especially when paired with generator expressions.
The time complexity of common operations on Python's many data structures.
Merging dictionaries in Python is usually as simple as a single pipe character.
Sets are unordered collections of values that are great for removing duplicates, quick containment checks, and set operations.
The in operator on lists can be slow. But why?
What happens when you loop over a dictionary? And should you loop over dictionaries?
A mapping is a dictionary-like object. Some mappings are mutable and some are immutable.
There is more than one way to remove a key-value pair from a dictionary in Python.
Dictionaries in Python maintain the insertion order of their keys.
Inserting an item to the beginning of a list is much slower than appending an item to the end of a list.
List items can be removed based on their value or position in the list. Removing from the end of a list using is the most common and efficient approach.
Data structures can be compared for equality in Python by using an equality check with the == operator.
Python lexicographically orders tuples, strings, and all other sequences, comparing element-by-element.
There are many ways to set default values for dictionary key lookups in Python. Which way you should use will depend on your use case.
My name is Trey Hunner. I publish new Python articles and screencasts every week through Python Morsels. If you want to learn something new about Python every week, join Python Morsels!