Re: formatting list -> comma separated (slightly different)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • egbert

    #1

    Re: formatting list -> comma separated (slightly different)

    On Wed, Jul 09, 2008 at 10:25:33PM +0200, Michiel Overtoom wrote:
    Formatting a sequence of items such that they are separated by
    commas, except the last item, which is separated by the word 'and'.
    >
    For example:
    >
    Three friends have a dinner: Anne, Bob and Chris
    row = ["Anne","Bob","C hris"]
    txt = ", ".join(row)
    pos = txt.rfind(", ")
    new = "%s and %s" % (txt[0:pos], txt[pos+2:])

    egbert
    --
    Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991
    =============== =============== =============== =============== ============
Working...