You should use a list when it makes sense to store items in order. In this case it only matters that ID's are mapped to names.
A dictionary is a mapping, which means the relation between keys and values is not symmetrical. For example, it's tricky (and not always possible in the general case) to fetch a key by known value, whereas it's equally easy to filter a list (or a set, for that matter) of tuples by value of any of their items.
That being said, when choosing the data structure, it makes sense to consider how you are going to retrieve data from it. If you can see id
and name
as equal parts of something resembling a C struct
(e.g. you'll need to search by any of them, etc.) then you're better off using a tuple or a collections.namedtuple
. You can still put them in a list or a set depending on your need to keep it ordered.
But if id
is a "special" field that is used to retrieve the rest of the info about the object, and it's guaranteed to be unique (well, "ID" means it), and you don't need internal order, and you want constant time random access -- of course use a dict.