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 Try >>> 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 http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor