11-47's picture choucsan's picture
Duplicate from choucsan/mimo-claude-code-traces-1k
aeb931a
|
Raw History Blame Contribute Delete
5.97 kB
Claude Code trace
User 2026-06-21T11:04:02.078Z

Convert this code to use dataclasses instead of the current approach:

python
def calculate(data):
    total = 0
    for item in data:
        if item['type'] == 'A':
            total += item['value'] * 1.1
        elif item['type'] == 'B':
            total += item['value'] * 0.9
        elif item['type'] == 'C':
            total += item['value'] * 1.05
    return total
Assistant mimo-v2.5-pro 2026-06-21T11:04:03.078Z 475↓ 270↑ (48,640 cached)
Thinking The user wants me to convert dictionary-based code to use dataclasses instead.

The user wants me to convert dictionary-based code to use dataclasses instead.

Assistant mimo-v2.5-pro 2026-06-21T11:04:05.078Z 475↓ 270↑ (48,640 cached)
Thinking Done.

Done.

Created calculator.py. Key changes:

  • Item dataclass with type and value fields, replacing bare dictionaries
  • adjusted_value property encapsulates the multiplier logic per item type
  • calculate is now a simple sum() over the adjusted values

Usage:

python
data = [Item("A", 100), Item("B", 200), Item("C", 50)]
result = calculate(data)
mimo-v2.5-pro Input 950↓ Input Cached 97.3k↓ (99%) Output 540↑