whats the best way to join an array into a readable list

Posted by Ross on Stack Overflow See other posts from Stack Overflow or by Ross
Published on 2010-04-27T18:41:41Z Indexed on 2010/04/27 18:43 UTC
Read the original article Hit count: 240

Filed under:
|
|

I've got an array listing days of the week:

days = ['Monday', 'Tuesday', 'Wednesday']

Whats the easiest / best way to output it in a human readable format:

Monday, Tuesday and Wednesday

The best I have is a rather ugly:

', '.join(days[:-2]+['']) + ' and '.join(days[-2:])

© Stack Overflow or respective owner

Related posts about python

Related posts about join