> Then within the loop you use the following construct: > > histogram[word] = histogram.get(word, 0) + 1 Why not this? if word in histogram: histogram[word] += 1 else: histogram[word] = 1 Isn't that crystal clear? Or, for that matter: if word not in histogram: histogram[word] = 0 histogram[word] += 1