It seems to me that dictionaries are encouraged to define classes and use classes. When should I use a dictionary over a class and vice versa?
For example, if I want to have a dictionary of people, and each person has a name and other attributes, two simple ways:
Create a dictionary of people. Each key will be a person’s name, and the value will be a dictionary of all the attributes that a person has.
Create a Person class that contains these attributes, and then enter the Person s dictionary, the name will be the key and the Person object.
Both solutions seem valid and achieve the goal, but still it seems that python dictionaries are the way to go. The implementations are quite different so that if I wanted to switch back and forth, I could start a lot of changes to move from a class-based implementation to a dictionary-based implementation and vice versa.
So what am I trading?
source share