You are viewing a single comment's thread. Return to all comments →
Nice solution. I had forgotten about Counter.
Counter
Anyways, I used defaultdict. I believe Counter uses this in its implementation.
defaultdict
from collections import defaultdict def ransom_note(magazine, ransom): dicty = defaultdict(int) for word in magazine: dicty[word]+=1 for word in ransom: if dicty[word]==0 : return False dicty[word]-=1 return True
Seems like cookies are disabled on this browser, please enable them to open this website
Hash Tables: Ransom Note
You are viewing a single comment's thread. Return to all comments →
Nice solution. I had forgotten about
Counter
.Anyways, I used
defaultdict
. I believe Counter uses this in its implementation.