def mostCommonName(L):
return 42 # place your answer here!
def testMostCommonName():
print("Testing mostCommonName()...", end="")
assert(mostCommonName(["Jane", "Aaron", "Cindy", "Aaron"])
== "Aaron")
assert(mostCommonName(["Jane", "Aaron", "Jane", "Cindy", "Aaron"])
== {"Aaron", "Jane"})
assert(mostCommonName(["Cindy"]) == "Cindy")
assert(mostCommonName(["Jane", "Aaron", "Cindy"])
== {"Aaron", "Cindy", "Jane"})
assert(mostCommonName([]) == None)
print("Passed!")
testMostCommonName()
def ct1(n): s, t = set(), set() while (n > 0): (d, n) = (n%10, n//10) if (d in t): t.remove(d) elif (d in s): t.add(d) s.add(d) return sorted(t) print(ct1(13051231)) def ct2(d, key): while (key in d) and ((key+2) not in d): d[key+2] = key+1 key = d[key] L = [ ] for key in sorted(d.keys()): L.append(10*key + d[key]) return L print(ct2({1:5, 0:2}, 0))
def rc1Helper(d): s = "" for key in d: if key % 2 == 0: s += d[key] return s def rc1(d): assert(sorted(d.keys()) == list(range(0,4))) s = rc1Helper(d) return s == "good luck!" def rc2(d): i = j = k = m = 0 for key in d: i += 1 value = d[key] if (key == value): j = min(value, j) k = max(value, k) else: m += 1 return ((i, j, k, m) == (4, -2, +2, 1))
d = dict() d["fred"] = set(["wilma", "betty", "barney"]) d["wilma"] = set(["fred", "betty", "dino"])With this in mind, write the function mostPopularFriend(d) that takes a dictionary of that form, and returns the name that occurs the most number of times in all the sets of friends. In the example above, mostPopularFriend(d) would return "betty". You may assume that there is exactly one such name, so ignore ties.