syntax philosophy
Andrew Koenig
ark at acm.org
Mon Nov 17 21:17:37 EST 2003
More information about the Python-list mailing list
Mon Nov 17 21:17:37 EST 2003
- Previous message (by thread): syntax philosophy
- Next message (by thread): syntax philosophy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 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
- Previous message (by thread): syntax philosophy
- Next message (by thread): syntax philosophy
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list