Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46624
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.05; 'argument': 0.05; 'mrab': 0.05; 'subject:Python': 0.06; '*not*': 0.07; 'attribute': 0.07; 'explicit': 0.07; 'granted,': 0.07; 'none:': 0.07; 'odd': 0.07; 'string': 0.09; 'subject:How': 0.10; 'def': 0.12; '(note:': 0.16; 'advocating': 0.16; 'argument,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterable': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'putting': 0.22; 'error': 0.23; 'bytes': 0.24; 'sort': 0.25; 'second': 0.26; 'pass': 0.26; 'least': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'forces': 0.31; 'sep': 0.31; 'file': 0.32; 'this.': 0.32; 'stuff': 0.32; '(most': 0.33; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:j 20': 0.36; 'subject:?': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'ian': 0.60; "you're": 0.61; 'first': 0.61; 'skip:n 10': 0.64; '30,': 0.65; 'default': 0.69; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=BV++R5mI8KFzbbaBO6PFqemrPJchTa0N8fv6df8WrY0=; b=SmodOw8n/edJ47xn3gHHcX6TbUtK2Ew6J2v8AB+FKTaxp4XAWuvlZfq0dkaXVLCSL5 t5QG8I9OkWt+E1sRc/hkLy7DNYKPiRllI0j+Y+MZqK6w+OaBxhhLlA0vceN9/Qe9f9FG v7K94qiGvq/b68P3Y9yDUAloe2JBNn+fBrORh/D2UDzawg9uCLpHcCx0ypBzA2ek1Naf ceDNED2dYxbK6P/o3oo1MsO5YSBeQFakOEZNDjVgI1FEj9a8yQ5E88jxYbN8cBBmLiqD xmPZbMXw4XtMOcgGDIA5Wd563UTEVB0V/TKlb0xeLdN4c2gNxxhWo1x1NDNwpORU+7Io A6ZA== |
| MIME-Version | 1.0 |
| X-Received | by 10.220.109.66 with SMTP id i2mr11408720vcp.51.1370026373703; Fri, 31 May 2013 11:52:53 -0700 (PDT) |
| In-Reply-To | <CALwzid=kRrojg6B6uy_PYiYrcm9tsGbKZrSF7eMuGOt89UFJTQ@mail.gmail.com> |
| References | <CAGVx7UWXAFHSHq37Ep-Vk=cM2wYrEGHSUhNc8s43bCvj_VcVow@mail.gmail.com> <CAGGBd_oT=vqvPGZy+d1H=XHjdPCmYUxJMXAwii7WH845xrYybQ@mail.gmail.com> <mailman.2389.1369876474.3114.python-list@python.org> <851ce96a-0223-42b0-8d99-902294c71f58@hc4g2000pbb.googlegroups.com> <CALwzidkvPJFWh1csV+sC6mFb9bZFaft_T5e+5E49eHucBTf-hQ@mail.gmail.com> <CAPTjJmqHE_Ctyn5dEL3TeXaan4_cF9JUWHi_hMb2nyafhpn5CQ@mail.gmail.com> <51A7AAC0.6080509@mrabarnett.plus.com> <CALwzid=kRrojg6B6uy_PYiYrcm9tsGbKZrSF7eMuGOt89UFJTQ@mail.gmail.com> |
| Date | Sat, 1 Jun 2013 04:52:53 +1000 |
| Subject | Re: How clean/elegant is Python's syntax? |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2501.1370026382.3114.python-list@python.org> (permalink) |
| Lines | 37 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370026382 news.xs4all.nl 15991 [2001:888:2000:d::a6]:42924 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:46624 |
Show key headers only | View raw
On Sat, Jun 1, 2013 at 1:43 AM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Thu, May 30, 2013 at 1:38 PM, MRAB <python@mrabarnett.plus.com> 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)
>
> One argument against the default is that it is specific to the str
> type. If you then tried to use join with an iterable of bytes objects
> and the default sep argument, you would get a TypeError. At least not
> having the default forces you to be explicit about which string type
> you're joining.
What about:
def join(iterable, sep=None):
if sep is not None: return sep.join(iterable)
iterable=iter(iterable)
first = next(iterable)
return first + type(first)().join(iterable)
Granted, it has some odd error messages if you pass it stuff that isn't strings:
>>> join([[1,2,3],[4,5,6]])
Traceback (most recent call last):
File "<pyshell#241>", line 1, in <module>
join([[1,2,3],[4,5,6]])
File "<pyshell#235>", line 5, in join
return first + type(first)().join(iterable)
AttributeError: 'list' object has no attribute 'join'
but you'd get that sort of thing anyway.
(NOTE: I am *not* advocating this. I just see it as a solution to one
particular objection.)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: How clean/elegant is Python's syntax? Ma Xiaojun <damage3025@gmail.com> - 2013-05-30 09:14 +0800
Re: How clean/elegant is Python's syntax? rusi <rustompmody@gmail.com> - 2013-05-29 19:49 -0700
Re: How clean/elegant is Python's syntax? Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-30 12:36 -0600
Re: How clean/elegant is Python's syntax? rusi <rustompmody@gmail.com> - 2013-05-30 11:47 -0700
Re: How clean/elegant is Python's syntax? John Ladasky <john_ladasky@sbcglobal.net> - 2013-05-30 15:01 -0700
Re: How clean/elegant is Python's syntax? Chris Angelico <rosuav@gmail.com> - 2013-05-31 04:44 +1000
Re: How clean/elegant is Python's syntax? Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-30 12:51 -0600
Re: How clean/elegant is Python's syntax? MRAB <python@mrabarnett.plus.com> - 2013-05-30 20:38 +0100
Re: How clean/elegant is Python's syntax? Chris Angelico <rosuav@gmail.com> - 2013-05-31 07:28 +1000
Re: How clean/elegant is Python's syntax? Ian Kelly <ian.g.kelly@gmail.com> - 2013-05-31 09:43 -0600
Re: How clean/elegant is Python's syntax? Chris Angelico <rosuav@gmail.com> - 2013-06-01 04:52 +1000
csiph-web