Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-13 Thread Florian Diesch
Ric Da Force [EMAIL PROTECTED] wrote: 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. import re data = the first bit, then

Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-12 Thread Ric Da Force
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 --

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-12 Thread Peter Otten
Ric Da Force wrote: 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. and.join(C1, C2, C3.rsplit(,, 1)) 'C1, C2 and C3'

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-12 Thread Christoph Rackwitz
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,

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-12 Thread Brian van den Broek
Ric Da Force said unto the world upon 12/07/2005 02:43: 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

Re: Replacing last comma in 'C1, C2, C3' with 'and' so that it reads 'C1, C2 and C3'

2005-07-12 Thread Cyril Bazin
If that can help you... def replaceLastComma(s): i = s.rindex(,) return ' and'.join([s[:i], s[i+1:]]) I don't know of ot's better to do a: ' and'.join([s[:i], s[i+1:]]) Or: ''.join([s[:i], ' and', s[i+1:]]) Or: s[:i] + ' and' + s[i+1] Maybe the better solution is not in the list... Cyril On