More on Lists
Lists have many useful methods:Example Usage
Methods like
insert, remove, and sort that only modify the list return None - this is a design principle for all mutable data structures in Python.Using Lists as Stacks
Lists work well as stacks (last-in, first-out):Using Lists as Queues
List Comprehensions
List comprehensions provide a concise way to create lists:Complex List Comprehensions
Combine elements from two lists:Nested List Comprehensions
Transpose a matrix:The del Statement
Remove items from a list by index:del can also delete entire variables:
Tuples and Sequences
A tuple consists of values separated by commas:Empty and Single-Item Tuples
Tuple Packing and Unpacking
Sets
A set is an unordered collection with no duplicates:Set Operations
Set Comprehensions
Dictionaries
Dictionaries are indexed by keys (any immutable type):Creating Dictionaries
From sequences:Looping Techniques
Looping Through Dictionaries
Looping with Index
Looping Over Multiple Sequences
Looping in Reverse
Looping in Sorted Order
More on Conditions
Comparison operators can be chained:and, or, and not:
Boolean operators are short-circuit: they stop evaluating as soon as the outcome is determined.
