You are viewing a single comment's thread. Return to all comments →
You can avoid using Counter and save space by only using one dictionary (space is len(set(a + b)) rather than len(a) + len(b)). My solution:
def number_needed(a, b): anagram_dict = dict.fromkeys(a + b, 0) for letter in a: anagram_dict[letter] += 1 for letter in b: anagram_dict[letter] -= 1 return sum([abs(val) for val in anagram_dict.values()])
Seems like cookies are disabled on this browser, please enable them to open this website
Strings: Making Anagrams
You are viewing a single comment's thread. Return to all comments →
You can avoid using Counter and save space by only using one dictionary (space is len(set(a + b)) rather than len(a) + len(b)). My solution: