2. Lists and Dictionaries
Many programs are written to automate repetitive tasks that are better suited to machines than to humans. In Python, the most common way to organize this kind of work is by using a sequence of values stored in a list
type. Lists are extremely versatile and can be used to solve a variety of problems.
A natural complement to lists is the dict
type, which stores lookup keys mapped to corresponding values (in what is often called an associative array or a hash table). Dictionaries provide constant time (amortized) performance for assignments and accesses, which means they are ideal for bookkeeping dynamic information.
Python has special syntax and built-in modules that enhance readability and extend the capabilities of ...
Get Effective Python: 90 Specific Ways to Write Better Python, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.