How clean/elegant is Python's syntax?

John Ladasky john_ladasky at sbcglobal.net
Thu May 30 18:01:20 EDT 2013


On Thursday, May 30, 2013 11:36:54 AM UTC-7, Ian wrote:

> 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.

That may all be true, but the join() function shown will return a sequence starting with iterable[0] (followed by sep, and then iterable[1], then sep, etc.).  I find it more natural to see iterable as the first argument passed to join() for that reason.  Season to taste, I guess.



More information about the Python-list mailing list