I'm currently writing a function that takes a dictionary with immutable values and returns an inverted dictionary. So far, my code is getting extremely simple tests right, but it still has some kinks to work out
def dict_invert(d): inv_map = {v: k for k, v in d.items()} return inv_map list1 = [1,2,3,4,5,6,7,8] list2 = {[1]:3245,[2]:4356,[3]:6578} d = {['a']:[],['b']:[]} d['a'].append(list1) d['b'].append(list2) How do I fix my code so that it passes the test cases?
My only thoughts are to change list 2 to [1:32, 2:43, 3:54, 4:65]; however, I would still have a problem with having the "[]" in the right spot. I have no idea how to do that.
list2and yourdshouldn't even run: lists aren't hashable, so you can't use them as dictionary keys.collections.defaultdict