You are viewing a single comment's thread. Return to all comments →
Nice. I need to learn how to use Counter!
My solution with defaultdict:
from collections import defaultdict def count_chars(word): counts = defaultdict(lambda: 0) for ch in word: counts[ch] += 1 return counts word1, word2 = count_chars(input()), count_chars(input()) allchars = set(list(word1.keys()) + list(word2.keys())) print(sum(abs(word1[ch] - word2[ch]) for ch in allchars))
Making Anagrams
You are viewing a single comment's thread. Return to all comments →
Nice. I need to learn how to use Counter!
My solution with defaultdict: