<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">OK Kent - got it:<DIV><BR class="khtml-block-placeholder"></DIV><DIV>My little formating function could be written as  (tested)  </DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>    def cellpos(pname, alvl, blvl, clvl):</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        # breakout path components into list  </DIV><DIV>         pl = pname.split('/')</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>        # insert empty cells for repeated names and</DIV><DIV>        #  add new path components (cells) to csvline</DIV><DIV>        csvline = '"",'*(alvl - blvl) + '"' + '","'.join(pl[alvl:clvl]) + '",'</DIV><DIV>  </DIV><DIV>        return csvline</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>"So, it is good to know about join(), but write the code the way that is clearest to you."</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>One of my thoughts in posting this exercise is to first understand alternatives before I decide what I like best :~) </DIV><DIV>Your points, together with Javier's points on presentation and thoroughness, and Liam's point on making the logic more obvious are appreciated. </DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Thank you all for taking the time to offer your comments,</DIV><DIV>Lee C</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><DIV><DIV>On Jun 5, 2005, at 5:47 AM, Kent Johnson wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Lee Cullens wrote:</DIV> <BR><BLOCKQUOTE type="cite"></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><FONT class="Apple-style-span" color="#006312">&lt;snip&gt;</FONT><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">OK, let's try to get this right.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Given a list of strings and a divider string, join() returns the strings from the list 'joined' by the divider string. For example,</DIV> <BR><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">pl = ['a', 'b', 'c']</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">'","'.join(pl)</DIV> <BR></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">'a","b","c'</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">The syntax for this takes a little getting used to; join() is actually a string method; you call it on the divider string and pass it the list of strings to be joined.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">To make a list of quoted, comma separated values, you also need initial and final quotes:</DIV> <BR><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">'"' + '","'.join(pl) + '"'</DIV> <BR></BLOCKQUOTE></BLOCKQUOTE></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">'"a","b","c"'</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">In your example you need '","'.join(pl[0:2])</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BR><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Saving one line of code in this module doesn't mean much,<SPAN class="Apple-converted-space">  </SPAN>but if it <SPAN class="Apple-converted-space"> </SPAN></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">were a efficiency in processing it would?</DIV> <BR></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Conventional wisdom is that it is more efficient to use the join method. More enlightened wisdom says, don't optimize until you know you have a problem, and the only way to know what is fastest in your program with your data is to test. And of course working code always beats broken code :-)</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I did some experiments with these alternatives and concluded that if the length of the resulting string is less than about 500-800, the version using += is faster than the one using join():</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://www.pycs.net/users/0000323/weblog/2004/08/27.html">http://www.pycs.net/users/0000323/weblog/2004/08/27.html</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">So, it is good to know about join(), but write the code the way that is clearest to you.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Kent</DIV></BLOCKQUOTE></DIV><FONT class="Apple-style-span" color="#0000DD"><BR class="khtml-block-placeholder"></FONT></DIV></BODY></HTML>