Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17306
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <roy@panix.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.080 |
| X-Spam-Evidence | '*H*': 0.84; '*S*': 0.00; 'framework.': 0.07; 'reply- to:addr:comp.lang.python': 0.09; 'to:addr:comp.lang.python': 0.09; 'essentially': 0.10; 'elements,': 0.16; 'guessing': 0.16; 'cc:addr :python-list': 0.16; 'header:In-Reply-To:1': 0.22; "i'm": 0.26; "skip:' 10": 0.29; 'cc:addr:python.org': 0.29; "i've": 0.31; 'cases': 0.32; "can't": 0.32; 'header:User-Agent:1': 0.33; 'this.': 0.33; 'there': 0.33; 'it.': 0.34; 'something': 0.35; 'subject:How': 0.35; 'post': 0.36; 'cc:2**1': 0.36; 'element': 0.37; 'two': 0.37; 'received:google.com': 0.37; 'some': 0.38; 'received:209.85': 0.38; 'received:209': 0.40; 'took': 0.63; 'saw': 0.67; 'care': 0.71; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:googlegroups.com': 0.74; 'post)': 0.84 |
| Newsgroups | comp.lang.python |
| Date | Thu, 15 Dec 2011 11:01:14 -0800 (PST) |
| In-Reply-To | <mailman.3690.1323975113.27778.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=66.114.87.114; posting-account=dAOV_goAAABEUkqpkMcBZ68KkIzfCnsO |
| References | <9393353.282.1323967703697.JavaMail.geo-discussion-forums@vbyc2> <4EEA35F8.4090502@tim.thechases.com> <4EEA3A47.5020106@stoneleaf.us> <mailman.3690.1323975113.27778.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| MIME-Version | 1.0 |
| Subject | Re: How to generate "a, b, c, and d"? |
| From | Roy Smith <roy@panix.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | Python <python-list@python.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| Reply-To | comp.lang.python@googlegroups.com |
| 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> |
| Message-ID | <mailman.3691.1323975683.27778.python-list@python.org> (permalink) |
| Lines | 18 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1323975683 news.xs4all.nl 6903 [2001:888:2000:d::a6]:52108 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:17306 |
Show key headers only | View raw
FWIW, I ended up with:
n = len(names)
if n == 0:
return ''
if n == 1:
return names[0]
pre = ', '.join(names[:-1])
post = names[-1]
return '%s, and %s' (pre, post)
the slice-and-join() takes care of both the 2 and >2 element cases at the same time :)
It would be nice if there were some standard way to do this. I'm sure I've seen something that was essentially a join() that took two delimiters; one for most elements, the other a special-case for the last one. I can't remember where I saw it. I'm guessing in some web framework.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to generate "a, b, c, and d"? Roy Smith <roy@panix.com> - 2011-12-15 08:48 -0800
Re: How to generate "a, b, c, and d"? MRAB <python@mrabarnett.plus.com> - 2011-12-15 17:27 +0000
Re: How to generate "a, b, c, and d"? Tim Chase <python.list@tim.thechases.com> - 2011-12-15 12:01 -0600
Re: How to generate "a, b, c, and d"? Ethan Furman <ethan@stoneleaf.us> - 2011-12-15 10:19 -0800
Re: How to generate "a, b, c, and d"? Tim Chase <python.list@tim.thechases.com> - 2011-12-15 12:51 -0600
Re: How to generate "a, b, c, and d"? Roy Smith <roy@panix.com> - 2011-12-15 11:01 -0800
Re: How to generate "a, b, c, and d"? Roy Smith <roy@panix.com> - 2011-12-15 11:01 -0800
Re: How to generate "a, b, c, and d"? MRAB <python@mrabarnett.plus.com> - 2011-12-15 19:27 +0000
Re: How to generate "a, b, c, and d"? Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-15 14:22 -0700
Re: How to generate "a, b, c, and d"? Terry Reedy <tjreedy@udel.edu> - 2011-12-15 19:57 -0500
Re: How to generate "a, b, c, and d"? Chris Angelico <rosuav@gmail.com> - 2011-12-16 13:42 +1100
Re: How to generate "a, b, c, and d"? Terry Reedy <tjreedy@udel.edu> - 2011-12-16 00:26 -0500
csiph-web