[Tutor] Dictionary Issue

Alan Gauld alan.gauld at btinternet.com
Fri Aug 7 01:20:15 CEST 2015

On 07/08/15 00:11, Ltc Hotspot wrote:
> Questions(1):Why does print line, prints blank space; and, (2) print 
> address prints a single email address:

See my previous emails.
You are not storing your addresses so address only holds the last 
address in the file.
line is at the end of the file so is empty.,

> In [72]: print count
> {'gopal.ramasammycook at gmail.com 
> <mailto:gopal.ramasammycook at gmail.com>': 1, 'louis at media.berkeley.edu 
> <mailto:louis at media.berkeley.edu>': 3, 'cwen at iupui.
> edu': 5, 'antranig at caret.cam.ac.uk <mailto:antranig at caret.cam.ac.uk>': 
> 1, 'rjlowe at iupui.edu <mailto:rjlowe at iupui.edu>': 2, 'gsilver at umich.ed
> u': 3, 'david.horwitz at uct.ac.za <mailto:david.horwitz at uct.ac.za>': 4, 
> 'wagnermr at iupui.edu <mailto:wagnermr at iupui.edu>': 1, 'zqian at umich.edu 
> <mailto:zqian at umich.edu>':
>  4, 'stephen.marquard at uct.ac.za <mailto:stephen.marquard at uct.ac.za>': 
> 2, 'ray at media.berkeley.edu <mailto:ray at media.berkeley.edu>': 1}
> Question(3): why did the elements print count('keys') and print 
> count('items') fail?

Because, as shown above, count is a dictionary.
So items and keys are methods not strings to be passed
to a non-existent count() function.

So you need, for example:

print count.keys()

> Traceback (most recent call last)
> <ipython-input-76-35c8707b256e> in <module>()
> ----> 1 print count('items')
> TypeError: 'dict' object is not callable

Which is what the error is also telling you.
You cannot call - ie use () - with a dictionary like count.

Alan G
Author of the Learn to Program web site
Follow my photo-blog on Flickr at:

More information about the Tutor mailing list