Due Tuesday 19-Oct, at 10:00pm
hw6.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 try/except or classes 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 starts this week, so please use good style from now on!
You will notice that the skeleton file does not include testcases. We advise you to write test cases. (You can find some nice ways to test in the write-up below, but you will need to translate those to actual testcases.)
A few notes on the problems marked recursive:
for
loops or while
on the problems marked recursive.invertDictionary(d)
that takes a dictionary
d
that maps keys to values and returns a dictionary of its inverse,
that maps the original values back to their keys. One complication: there can be
duplicate values in the original dictionary. That is, there can be keys
k1
and k2
such that (d[k1] == v) and (d[k2] ==
v)
for the same value v
. For this reason, we will in fact
map values back to the set of keys that originally mapped to them. So, for
example:
paths
, where paths[cityA] =
cityB
means there exists a direct path going from cityA
to cityB
. Return the destination city, that is, the city without
any path outgoing to another city.
It is guaranteed that the paths form a line without any loop, therefore, there
will be exactly one destination city.
Consider the following examples:
S
, group the anagrams together.
Two strings are anagrams if each can be reordered into the other. Treat "a" and
"A" as the same letters (so "Aba" and "BAA" are anagrams).
The function should return a list of groups, in any order. Each group is a set
of strings where all the strings are anagrams of each other.
Some examples:
groupAnagrams(S)
will group the strings in the following way:
[{"bat"},{"nat","tan"},{"ate","eat","tea"}]
groupAnagrams(S)
will group the strings in the following way:
[{"own", "now"}, {"read","dare"}, {"eat","tea"}, {"stop", "spot"}, {"15112"}]The order of the groups in the returned list is not important. The size of
S
will be large, therefore you should avoid using lists
operations as much as possible, otherwise your solution will be too slow and
will timeout. We expect that your code processes an input of 30K words in less
than a minute.
True
if the
string is palindrome, False
otherwise.
For example,