What to do after Python?
Kenneth Loafman
ken at lt.com
Mon Feb 19 08:41:40 EST 2001
Roy Smith wrote:
>
> Kenneth Loafman <ken at lt.com> wrote:
> > Consider one case I found
> > where the goal was to remove the last character of a line. Instead of
> > using something like:
> >
> > if (strlen(s)) s[strlen(s)-1] = 0
> >
> > the (7-year C++ veteran) wrote several lines of code that:
> >
> > reversed the string
> > trimmed the first char
> > re-reversed the string
>
> How about:
>
> if (length = strlen(s))
> s[length-1] = 0;
>
> and cut your instruction count in half :-)
AArgh! Been doing Python too long! You can't assign in an if statement
in Python, so the awkward construct represented the worst of both. In
retrospect, I'd probably write something like:
if (s[0])
s[strlen(s)-1] = 0
...Ken
More information about the Python-list
mailing list