In article <4c687936$0$11100$c3e8...@news.astraweb.com>, Steven D'Aprano <st...@remove-this-cybersource.com.au> wrote:
> On Sun, 15 Aug 2010 12:10:10 -0700, Steven Howe wrote: > > >> Strings have a join method for this: > >> '\t'.join(someList) > >> > >> Gary Herron > > or maybe: > > ----------------------------------------- > > res = "" > > for item in myList: > > res = "%s\t%s" % ( res, item ) > > > Under what possible circumstances would you prefer this code to the built- > in str.join method? > > Particularly since the code isn't even correct, as it adds a spurious tab > character at the beginning of the result string. I think you answered your own question. The possible circumstance would be a "find the bug" question on a programming interview :-) Actually, there is (at least) one situation where this produces the correct result, can you find it? The other problem is that the verbose version is O(n^2) and str.join() is O(n). -- http://mail.python.org/mailman/listinfo/python-list