9.4. What data type for which collection

We have seen so far three collection types in Python. Which one should you chose in your applications? Because they all have their advantages and disadvantages making some actions easy or difficult to handle, the choice depends on your data and on what you would do with these data. To recognize strings is the easiest one, but be aware if you need to change characters, since you will have to construct a new string. So a mutable ordered collection datatype, such as a list, could be more adapted.

For list and dictionaries there are two important issues to consider:

  1. Does the ordering of your collection matter?
  2. Is it sufficient to access the elements by their position or do you prefer to access the collection with a more complex, sometimes more descriptive, key rather than a number?

If you need an ordered collection you do not have any choice left, because only lists take care of the ordering. However the way of accessing a collection is sometimes not so easy and often worth further consideration.