How clean/elegant is Python's syntax?

Chris Angelico rosuav at gmail.com
Thu May 30 14:44:42 EDT 2013


On Fri, May 31, 2013 at 4:36 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
> On Wed, May 29, 2013 at 8:49 PM, rusi <rustompmody at gmail.com> wrote:
>> On May 30, 6:14 am, Ma Xiaojun <damage3... at 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)

Trouble is, it makes some sense either way. I often put the larger
argument first - for instance, I would write 123412341324*5 rather
than the other way around - and in this instance, it hardly seems as
clear-cut as you imply. But the function can't be written to take them
in either order, because strings are iterable too. (And functions that
take args either way around aren't better than those that make a
decision.)

ChrisA



More information about the Python-list mailing list