On May 30, 11:36 pm, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Wed, May 29, 2013 at 8:49 PM, rusi <rustompm...@gmail.com> wrote: > > On May 30, 6:14 am, Ma Xiaojun <damage3...@gmail.com> wrote: > >> What interest me is a one liner: > >> print '\n'.join(['\t'.join(['%d*%d=%d' % (j,i,i*j) for i in > >> range(1,10)]) for j in range(1,10)]) > > > Ha,Ha! The join method is one of the (for me) ugly features of python. > > You can sweep it under the carpet with a one-line join function and > > then write clean and pretty code: > > > #joinwith > > def joinw(l,sep): return sep.join(l) > > I don't object to changing the join method (one of the more > shoe-horned string methods) back into a function, but to my eyes > you've got the arguments backward. It should be: > > def join(sep, iterable): return sep.join(iterable) > > Putting the separator first feels more natural to me because I expect > the separator to usually be short as compared to the iterable, which > is often a longer expression (as is the case in both of your > subsequent usages). Placing the separator first also preserves > consistency of interface with the str.join and bytes.join functions, > as well as the older string.join function.
This is a subjective view of course... My problem is not method vs function but the order. Ive seen/used join dozens of times. Yet I find "".join(["apple","bear","cat"]) backkwards as compared to ["apple","bear","cat"].join("") The consistency is a separate question -- not arguing about that. Just that I dont like the look -- http://mail.python.org/mailman/listinfo/python-list