[pythonvis] Re: Part 2: How to split line into words and count them

  • From: "Richard Dinger" <rrdinger@xxxxxxxxxx>
  • To: <pythonvis@xxxxxxxxxxxxx>
  • Date: Thu, 22 May 2014 15:35:37 -0700

Unfortunately your approach will raise a KeyError the first time you encounter 
a specific word since that word is not in the dictionary.  Thus the get method, 
which has a default if the key is not in the dictionary will work.

From: Gabriele Battaglia 
Sent: Thursday, May 22, 2014 12:23 PM
To: pythonvis@xxxxxxxxxxxxx 
Subject: [pythonvis] Re: Part 2: How to split line into words and count them


Il giorno 22/mag/2014, alle ore 18:03, Richard Dinger <rrdinger@xxxxxxxxxx> ha 
scritto:


  wordMap[word] = wordMap[word] + 1


GB: or, better 

wordMap[word]  += 1


— 
Namasté!
Sent from my iMac27. (Libero)

Other related posts: