18.11.2014 Views

Zelle - Chapter 11.pdf - CTools

Zelle - Chapter 11.pdf - CTools

Zelle - Chapter 11.pdf - CTools

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Dictionary<br />

Counting<br />

• Since it is an error to<br />

reference a key which is not<br />

in the dictionary<br />

• We can use the dictionary get<br />

() operation and supply a<br />

default value if the key does<br />

not exist to avoid the error<br />

and get our count started.<br />

>>> ccc = dict()<br />

>>> print ccc.get("csev", 0)<br />

0<br />

>>> ccc["csev"] = ccc.get("csev",0) + 1<br />

>>> print ccc<br />

{'csev': 1}<br />

>>> print ccc.get("csev", 0)<br />

1<br />

>>> ccc["csev"] = ccc.get("csev",0) + 1<br />

>>> print ccc<br />

{'csev': 2}<br />

dict.get(key, defaultvalue)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!