How to delete a ast character from a string?
cvrebert+clp at gmail.com
Fri Aug 29 20:40:15 CEST 2008
On Fri, Aug 29, 2008 at 11:25 AM, <dudeja.rajat at gmail.com> wrote:
> I've a list some of whose elements with character \.
> I want to delete this last character from the elements that have this
> character set at their end,
> I have written a small program, unfortunately this does not work:
> dirListFinal = 
> for item in dirList:
> print item
> if item.endswith('\\') == True:
You san simplify that line to just:
> item = item[0:-1] # This one I googled and
> found to remove the last character /
And you don't need the leading 0, so just use:
item = item[:-1]
And those last 3 lines are a bit redundant. Just put one
at the same indentation level as the "if" and delete those 3 lines.
Not that these changes will necessarily fix your program, but they do
make it easier to comprehend for the reader.
> item.endswith() does not seem to be working.
> Please help
More information about the Python-list