Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46582 > unrolled thread
| Started by | Alister <alister.ware@ntlworld.com> |
|---|---|
| First post | 2013-05-31 09:08 +0000 |
| Last post | 2013-05-31 09:39 -0600 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
Re: How clean/elegant is Python's syntax? Alister <alister.ware@ntlworld.com> - 2013-05-31 09:08 +0000
Re: How clean/elegant is Python's syntax? Fábio Santos <fabiosantosart@gmail.com> - 2013-05-31 11:16 +0100
Re: How clean/elegant is Python's syntax? rusi <rustompmody@gmail.com> - 2013-05-31 03:27 -0700
Re: How clean/elegant is Python's syntax? Alister <alister.ware@ntlworld.com> - 2013-05-31 11:52 +0000
Re: How clean/elegant is Python's syntax? Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-31 09:39 -0600
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Date | 2013-05-31 09:08 +0000 |
| Subject | Re: How clean/elegant is Python's syntax? |
| Message-ID | <vMZpt.7049$2I2.2738@fx17.am4> |
On Thu, 30 May 2013 20:38:40 +0100, MRAB wrote:
> On 30/05/2013 19:44, Chris Angelico wrote:
>> On Fri, May 31, 2013 at 4:36 AM, Ian Kelly <ian.g.kelly@gmail.com>
>> wrote:
>>> On Wed, May 29, 2013 at 8:49 PM, rusi <rustompmody@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)
>>
>> 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.)
>>
> And additional argument (pun not intended) for putting sep second is
> that you can give it a default value:
>
> def join(iterable, sep=""): return sep.join(iterable)
I think that is the winning argument.
Next question is what should be the default ("", " " or',')?
--
Nasrudin walked into a teahouse and declaimed, "The moon is more useful
than the sun."
"Why?", he was asked.
"Because at night we need the light more."
[toc] | [next] | [standalone]
| From | Fábio Santos <fabiosantosart@gmail.com> |
|---|---|
| Date | 2013-05-31 11:16 +0100 |
| Message-ID | <mailman.2483.1369995864.3114.python-list@python.org> |
| In reply to | #46582 |
On Fri, May 31, 2013 at 10:08 AM, Alister <alister.ware@ntlworld.com> wrote:
> I think that is the winning argument.
> Next question is what should be the default ("", " " or',')?
join, comma_join, whitejoin, linejoin variants, with different defaults?
--
Fábio Santos
[toc] | [prev] | [next] | [standalone]
| From | rusi <rustompmody@gmail.com> |
|---|---|
| Date | 2013-05-31 03:27 -0700 |
| Message-ID | <51ff2721-d27e-466e-83e4-9ecc877d5583@fq2g2000pbb.googlegroups.com> |
| In reply to | #46582 |
On May 31, 2:08 pm, Alister <alister.w...@ntlworld.com> wrote:
> On Thu, 30 May 2013 20:38:40 +0100, MRAB wrote:
> > And additional argument (pun not intended) for putting sep second is
> > that you can give it a default value:
>
> > def join(iterable, sep=""): return sep.join(iterable)
>
> I think that is the winning argument.
Yes
> Next question is what should be the default ("", " " or',')?
Hmm... Never thought there was any choice here except "". Yes can see
the case for each.
[toc] | [prev] | [next] | [standalone]
| From | Alister <alister.ware@ntlworld.com> |
|---|---|
| Date | 2013-05-31 11:52 +0000 |
| Message-ID | <L90qt.8321$RF7.3110@fx07.am4> |
| In reply to | #46592 |
On Fri, 31 May 2013 03:27:52 -0700, rusi wrote:
> On May 31, 2:08 pm, Alister <alister.w...@ntlworld.com> wrote:
>> On Thu, 30 May 2013 20:38:40 +0100, MRAB wrote:
>> > And additional argument (pun not intended) for putting sep second is
>> > that you can give it a default value:
>>
>> > def join(iterable, sep=""): return sep.join(iterable)
>>
>> I think that is the winning argument.
>
> Yes
>
>> Next question is what should be the default ("", " " or',')?
>
> Hmm... Never thought there was any choice here except "". Yes can see
> the case for each.
to be fair "" is probably the most sensible although in my programs most
joins are using ','
--
We are governed not by armies and police but by ideas.
-- Mona Caird, 1892
[toc] | [prev] | [next] | [standalone]
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Date | 2013-05-31 09:39 -0600 |
| Message-ID | <mailman.2494.1370015234.3114.python-list@python.org> |
| In reply to | #46582 |
On Fri, May 31, 2013 at 4:16 AM, Fábio Santos <fabiosantosart@gmail.com> wrote:
> On Fri, May 31, 2013 at 10:08 AM, Alister <alister.ware@ntlworld.com> wrote:
>> I think that is the winning argument.
>> Next question is what should be the default ("", " " or',')?
>
> join, comma_join, whitejoin, linejoin variants, with different defaults?
The more specific versions should not even have the parameter as an
argument that can be supplied. Otherwise you could do:
comma_join(words, sep=';')
which is just unclear, and there is no reason to allow it.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web