I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, a, b,
c, and d (I'll settle for no comma after 'c'). Is there some standard way to
do this, handling all the special cases?
[] == ''
['a'] == 'a'
['a', 'b'] == 'a and b'
['a', 'b', 'c', 'd'] == 'a, b, and c'
It seems like
On 15/12/2011 16:48, Roy Smith wrote:
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, a, b, c, and
d (I'll settle for no comma after 'c'). Is there some standard way to do this,
handling all the special cases?
[] == ''
['a'] == 'a'
['a', 'b'] == 'a and b'
['a', 'b',
On 12/15/11 10:48, Roy Smith wrote:
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string, a, b, c, and
d (I'll settle for no comma after 'c'). Is there some standard way to do this,
handling all the special cases?
[] == ''
['a'] == 'a'
['a', 'b'] == 'a and b'
['a', 'b',
Tim Chase wrote:
On 12/15/11 10:48, Roy Smith wrote:
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string,
a, b, c, and d (I'll settle for no comma after 'c'). Is there some
standard way to do this, handling all the special cases?
[] == ''
['a'] == 'a'
['a', 'b'] == 'a
On 12/15/11 12:19, Ethan Furman wrote:
Tim Chase wrote:
On 12/15/11 10:48, Roy Smith wrote:
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string,
a, b, c, and d (I'll settle for no comma after 'c'). Is there some
standard way to do this, handling all the special cases?
If
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
On 15/12/2011 18:51, Tim Chase wrote:
On 12/15/11 12:19, Ethan Furman wrote:
Tim Chase wrote:
On 12/15/11 10:48, Roy Smith wrote:
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the
string, a, b, c, and d (I'll settle for no comma after 'c').
Is there some standard way to do this,
On Thu, Dec 15, 2011 at 11:51 AM, Tim Chase
python.l...@tim.thechases.com wrote:
For the fun/challenge? Because you have a REALLY big data source that you
don't want to keep in memory (in addition the resulting string)?
If you have that much data, then I question why you would want to
build
On 12/15/2011 12:27 PM, MRAB wrote:
On 15/12/2011 16:48, Roy Smith wrote:
I've got a list, ['a', 'b', 'c', 'd']. I want to generate the string,
a, b, c, and d (I'll settle for no comma after 'c'). Is there some
standard way to do this, handling all the special cases?
[] == ''
['a'] == 'a'
On Fri, Dec 16, 2011 at 11:57 AM, Terry Reedy tjre...@udel.edu wrote:
items[-1] = and + items[-1]
return , .join(items)
This works only if you're sure there are at least two items, and if
you don't mind two items coming out as a, and b.
ChrisA
--
On 12/15/2011 9:42 PM, Chris Angelico wrote:
On Fri, Dec 16, 2011 at 11:57 AM, Terry Reedytjre...@udel.edu wrote:
items[-1] = and + items[-1]
return , .join(items)
This works only if you're sure there are at least two items, and if
you don't mind two items coming out as a, and b.
11 matches
Mail list logo