On 16/01/16 22:53, boB Stepp wrote: >> The function plumbs the depths of thing according to the indices >> supplies in loc. The shape of thing must match the length of loc. > > The interesting part of this function for me was not the OP's original > questions, but why this particular use of a recursive function (Am I > using the proper terminology here?)?
Yes it's a recursive function. > Can someone provide a practical > use of this type of function where some more straightforward > searching/parsing approach would be ineffective? In fact its much easier to write this using recursion that any other method. Its just very difficult to use and so needs some protection. The difficulty is in getting the input data structures to match, once that's done the function itself is very straightforward. It's a way of quickly navigating a tree structure where the route to the node (or subtree) of interest is given in advance. Think of 'loc' as being a directory path broken into its individual parts and 'thing' as being the file system represented as a dictionary of dictionaries (for the named indexing to work). [BTW I haven't tried that to see if it works it's just a guess at a possible application...] Of course, for a real filesystem we have functions in the os module to do the work but that type of data structure might be the target. -- 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