How to generate "a, b, c, and d"?

Terry Reedy tjreedy at udel.edu
Fri Dec 16 00:26:10 EST 2011


On 12/15/2011 9:42 PM, Chris Angelico wrote:
> On Fri, Dec 16, 2011 at 11:57 AM, Terry Reedy<tjreedy at 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".

Please read the context that you removed.
The original second return line and my replacements come after

if len(items) <= 2:
   return " and ".join(items)

-- 
Terry Jan Reedy




More information about the Python-list mailing list