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

24th May 2020, 10:06 AM
nichdiomajadoch
1 Odpowiedź
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.
24th May 2020, 8:04 PM
John Wells
John Wells - avatar