foo = "C1, C2, C3" foo = foo.split(", ") # ['C1', 'C2', 'C3'] foo = ", ".join(foo[:-1]) + " and " + foo[-1] # just slicing and joining it
you can always look for something here: http://docs.python.org/lib/lib.html and there: http://docs.python.org/ref/ if you want to know, what methods an object has, try this (i shortened the output a bit): >>> foo = "C1, C2, C3" >>> dir(foo) ['__add__', '__doc__', ..., 'capitalize', 'center', 'count', 'decode','encode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill'] >>> -- http://mail.python.org/mailman/listinfo/python-list