5.7. Design Principles

There is an old saying in computing that I heartily agree with: “If you have a lot of special cases, the design is wrong.”

Apply this maxim to Python and the inescapable conclusion is that the design is pretty much right! Python has very few special cases, very few “gotchas,” very few “deadly sins” to watch out for. A big part of Python's clean design is that a number of key ideas are applied everywhere. Among these principles are the following:

  • Use lists as a general-purpose data structure.

  • If you need to look something up, use a dictionary.

  • Program the interface, not the implementation.

In the sections that follow, we look at each of these ideas in turn.

5.7.1. Key Idea: Use Lists as a General-Purpose Data Structure

As ...

Get XML Processing with Python 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.