[Tutor] Lists of duplicates

Alan Gauld alan.gauld at yahoo.co.uk
Thu Mar 9 04:10:22 EST 2017

On 09/03/17 06:06, Alex Kleider wrote:

> It seems you are simply kicking the can down the road rather than 
> explaining how it it is that dot notation actually works.

The dot notation is just a method access. Dictionaries
are like any other object and have many methods.

> To access a dictionary item one must specify it by name_of_dict[key].

What makes you think so? There are many ways to access a
dictionary, one of which is to use [key]. But there are
several methods too and the methods, especially get()
are often preferable


>>> help({})

for more.

> What Allan is (and you also are) doing is using dot notation.
> Your example uses side effects (which I've been lead to believe is a no 
> no.)

There is a side-effect involved in setdefault() and to
be honest I had to do a test before writing my code to
be sure that the append() would actually make it back
into the dictionary. But there are several Python
library features that involve side effects with,
perhaps, the list.sort() method being most obvious.

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

More information about the Tutor mailing list