Built-in Data Structures – list, set, dict

In this chapter we'll look at the following recipes:

  • Choosing a data structure
  • Building lists – literals, appending, and comprehensions
  • Slicing and dicing a list
  • Deleting from a list – deleting, removing, popping, and filtering
  • Reversing a copy of a list
  • Using set methods and operators
  • Removing items from a set – remove(), pop(), and difference
  • Creating dictionaries – inserting and updating
  • Removing from dictionaries – the pop() method and the del statement
  • Controlling the order of dict keys
  • Handling dictionaries and sets in doctest examples
  • Understanding variables, references, and assignment
  • Making shallow and deep copies of objects
  • Avoiding mutable default values for function parameters

Get Modern Python Cookbook 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.