0
What makes dataclasses preferable to dict
Hello, I copied this code from python docu. When should one use it instead of dictionary. I see no improvement against dict. https://code.sololearn.com/cDPIFyKS43WR/?ref=app
1 Answer
0
Your data class example has a method and multiple properties. Dictionaries have a key and a value only so two properties stored in a list structure. They serve two different purposes. You could maintain your group of dataclasses in a dictionary using name as the key and the class as the value. The dataclass would have difficulty replacing the dictionary.