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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.