syntax philosophy

Andrew Koenig ark at acm.org
Mon Nov 17 21:17:37 EST 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