I've gone ahead and created a script that does this, however it also strips punctuation. I was originally just comparing each character to a string containing a single space ' ' but even using s[-1].isspace() I lose punctuation marks. Any idea why that's happening?
(Not the OP, I just thought this would be interesting to do) Bob Nienhuis wrote: > BTW, GMail brings up some interesting sponsored links when the subject > line > has string.strip in it ( :-0) > > On 9/30/07, *Alan Gauld* < [EMAIL PROTECTED] > <mailto:[EMAIL PROTECTED]>> wrote: > > > "wesley chun" < [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote > in message > news:[EMAIL PROTECTED] > >> > I'm not sure how to proceed. My biggest stumbling > >> > block is how to detect the leading and trailing > >> > whitespace. > >> > >> Use indexing. > >> Try using a while loop. > >> Or maybe two? > >> > >> And strings have an isspace method... > > > > unfortunately, the isspace() string method only returns True if all > > chars in the string are whitespace chars and False otherwise, so > > that's a bummer. > > But the string can be one character long: > > s = 'fred\n' > print s[-1].isspace() # --> True > > :-) > > Alan G > > > _______________________________________________ > Tutor maillist - Tutor@python.org <mailto:Tutor@python.org> > http://mail.python.org/mailman/listinfo/tutor > > > ------------------------------------------------------------------------ > > _______________________________________________ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ------------------------------------------------------------------------ > > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.5.488 / Virus Database: 269.13.35 - Release Date: 29/09/2007 12:00 > AM > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor