Due Monday 7-Feb, at 10:00pm
hw4.py
file includes test functions to help you test on your own before
you submit to Gradescope. When you run your file, problems will be tested in order. If
you wish to temporarily bypass specific tests (say, because you have not yet completed
some functions), you can comment out individual test function calls at the bottom
of your file in main()
. However, be sure to uncomment and test everything together
before you submit! Ask a CA if you need help with this.Do not use sets, dictionaries, try/except, classes, or recursion this week. The autograder (or a manual CA review later) will reject your submission entirely if you do.
Like in the previous assignment, we will be grading your code based on whether it follows the 15-112 style guide. We may deduct up to 10 points from your overall grade for style errors. We highly recommend that you try to write clean code with good style all along, rather than fixing your style issues at the end. Good style helps you code faster and with fewer bugs. It is totally worth it. In any case, style grading already started, so please use good style from now on!
You will notice that the skeleton file only includes testcases for some of the functions you are writing. You should write testcases for the others. (You can find some nice ways to test in the write-up below, but you will need to translate those to actual testcases.)
destructiveRemoveRepeats
function below. Instead, you must
create the resulting list from scratch here. Also, note
that the autograder has no way to check this, so our CA's will
check this manually after the hw deadline.nondestructiveRemoveRepeats(L)
, which
takes a list L and nondestructively returns a new list in
which any repeating elements in L are removed. For example:
nondestructiveRemoveRepeats(L)
and then somehow remove all the elements in L and then
append the elements from that call. Instead, you must
destructively modify the list as you go. Also, again, note
that the autograder has no way to check this, so our CA's will
check this manually after the hw deadline.destructiveRemoveRepeats(L)
, which implements the
same function destructively. Thus, this function should directly modify
the provided list to not have any repeating elements. Since this
is a destructive function, it should not return any value at all
(so, implicitly, it should return None).
For example:
mostFrequentLetters(s)
, that takes a string s, and ignoring case (so "A" and "a" are treated the same), returns a lowercase string containing the letters of s in most frequently
used order. (In the event of a tie between two letters, follow alphabetic order.)
So:
s
does not contain any alphabetic characters, the result should be the empty string (""
).
rotateStringLeft(s, n)
that takes a string s and a
possibly-negative integer n. If n is non-negative, the function
returns the string s rotated n places to the left.
If n is negative, the function
returns the string s rotated |n| places to the right. So, for example:
isRotation(s, t)
that takes two possibly-empty strings and returns True if one is a rotation of the other. Note that a string
is not considered a rotation of itself.letterScores
, which is length 26, where letterScores[i]
contains
the point value for the tile that represents the ith character in the alphabet
(so letterScores[0]
contains the point value for tile a
) (pretty much as it
works in actual Scrabble).
bestScrabbleScore(dictionary,
letterScores, hand)
that takes 3 lists -- dictionary
(a list
of lowercase words), letterScores
(a list of 26 integers), and
hand
(a list of lowercase characters plus zero or more blank tiles
represented by *
) -- and returns a tuple of the highest-scoring
word in the dictionary that can be formed by some arrangement of some subset of
tiles in the hand, followed by its score. In the case of a tie, the first
element of the tuple should instead be a list of all such words in the order
they appear in the dictionary. If no such words exist, return
None
.*
), which acts as a wildcard and allows to form longer (and higher score) words.
oldest
(using the wildcard in place of s
) and toledo
(using the wildcard in place of an additional o
).
w
, and you have a single hand h
, could you write a function f(w,h)
(perhaps with a better name) that tells you whether or not that word could be constructed using that hand? And how might you use that function to help solve this problem?