Optimizing a text statistics function

Nickolay Kolev nmkolev at uni-bonn.de
Wed Apr 21 12:18:16 EDT 2004


Dennis Lee Bieber wrote:

> ##	for x in strippedWords:
> ##		unique[x] = 0
> ##
> ##	for x in strippedWords:
> ##		unique[x] += 1
> 
> 	for x in strippedWords:
> 		unique[x] = unique.get(x, 0) + 1


Just the thing I was looking for. :-)

To clarify:

unique.get(x, 0)

This says *give me the value of unique[x] if it exists, else give me 0*. 
Correct?



More information about the Python-list mailing list