Ric Da Force wrote: > Hi, > > I have a string such as 'C1, C2, C3'. Without assuming that each bit of > text is of fixed size, what is the easiest way to change this list so that > it reads: > 'C1, C2 and C3' regardless of the length of the string. > > Regards and sorry for the newbie question, > > Ric > > Use rfind and slicing:
>>> x = "C1, C2, C3"
>>> x[:x.rfind(',')]+' and'+x[x.rfind(',')+1:]
'C1, C2 and C3'
HTH,
Wolfram
--
http://mail.python.org/mailman/listinfo/python-list
