From 4fe9b95eda0c7fc89ef224f089e99331cd6067c2 Mon Sep 17 00:00:00 2001 From: Chris Proctor Date: Fri, 1 Mar 2024 20:39:18 -0500 Subject: [PATCH] Add assessment --- assessment.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 assessment.md diff --git a/assessment.md b/assessment.md new file mode 100644 index 0000000..327a737 --- /dev/null +++ b/assessment.md @@ -0,0 +1,32 @@ +# Dice Lab Assessment + +Everything works as expected. Nice work! + +## Comments + +I love your decision to comment your code, and to write the generalized +function `findn`. Within that function, your loop iterating over die +faces works fine, but checking whether `nmuch[die]` is initialized +will become tiresome after a while. There's a nice idiom for this, +using defaultdict. A defaultdict is like a normal dict, but when you +first access a key, its value is initialized for you if it's not +already present. + +``` +from collections import defaultdict + +def findn(self, nofakind): + nmuch = defaultdict(int) + for die in dice.faces(): + nmuch[die] += 1 + if nmuch[die] == nofakind: + return True + return False +``` + +Just a little cleaner :) + +Within your `yachtzee_goals`, I'm guessing that you probably had a feeling +that copying the same method over into multiple classes wasn't the best way +to do it--this would be a perfect place to use a subclass or a mixin, +python's approach to inheritance and multiple inheritance respectively.