You are viewing a single comment's thread. Return to all comments →
Interesting. Do you know why defaultdict is faster. From what I understand, defaultdict is very similar to Counter except that if we call a missing key, the defaultdict will include that key in its key set while Counter does not, which means defaultdict cost more operations and thus cost more time? (I'm a total newbie to computer science so excuse me for my naive question
Actually I'm not sure why but I tested dictionary types a few times in competitions to save a few secs and defaultdict had been always fastest. Weird thing is your use of counter is same with defaultdict but according to python.org it's same with Dict. Here is one of the test links I found, some others says speed difference is bigger.