Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Object-Oriented Python Dice Roller Yatzy Scoring

Henry Lin
Henry Lin
11,636 Points

_by_value function?

In _by_value function, Kenneth did

for die in self:
    if die == value: 
        do something
   return dice

Does die == value work because he overrode __eq__ method in dice.py? Also return dice would return the actual number of each die's face is because he overrode __reper__ right?

[MOD: added formatting -cf]

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

Does die == value work because he overrode __eq__ method in dice.py? Correct!

Also return dice would return the actual number of each die's face is because he overrode __repr__ right? In the _by_value method, "dice" is a list that will contain all of the die matching value append to the list.

In re-scanning the videos, I did not see where __repr__ was overridden.

Post back if you have more questions!

Johannes Scribante
Johannes Scribante
19,175 Points

Just to clarify, Hand() is a subclass of list and is not a subclass of Die(). In Die() the __repr__ was overridden, but even though Hand() contains a list of many Die() instances the __repr__ was not overridden in Hand().

We can however equate die == value because the list of Die() in Hand() each Die() instance is part of the Die class which has overridden the __eq__ magic method and therefore we can equate die == value?

Please correct me if I am wrong, I would just like to make sure I understand correctly