It seems to me that dictionaries are encouraged over defining classes and using classes. When should I use a dictionary over a class and the other way around?
For example if I want to have a dictionary of people and each person has a name and other attributes, two simple ways would be:
Create a dictionary of the people. Each key will be the persons name and the value will be a dictionary of all the attributes that person has.
Create a class
Person
that contains those attributes and then have a dictionary ofPerson
s, have the name be the key and thePerson
object the value.
Both solutions seem valid and accomplish the goal, but it still seems as though dictionaries in python would be the way to go. The implementations are different enough that if I wanted to switch back and forth I could run into many changes to go from a class based implementation to a dictionary based implementation and vice versa.
So what am I trading off?