[Tutor] storing and saving file tree structure

Alan Gauld alan.gauld at yahoo.co.uk
Mon Jan 25 19:55:06 EST 2021


On 25/01/2021 09:20, mhysnm1964 at gmail.com wrote:

> As indents are a visual formatting structure. It is difficult for a screen
> reader user like myself to keep the blocks of code correctly indented. Thus
> why I am using the comments at the end of the code.

Ah, that makes sense. You just need to bear in mind the traps
that they introduce of prematurely ending blocks and
inadvertently chopping blocks into pieces.

> I will check out sets as that sounds useful. 

OK, Also don;t forget the setdefault() method of dicts which is what
saves you from having to check for membership...

books.setdefault(anAuthor, set()).add(book)

Will always work because setdefault() returns the existing
set for an existing key and adds (and returns) a new empty
set for a non-existent key.

-- 
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




More information about the Tutor mailing list