syntax philosophy

Andrew Koenig ark at acm.org
Tue Nov 18 03:17:37 CET 2003


> 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






More information about the Python-list mailing list