invert or reverse a string... warning this is a rant
skip at pobox.com
skip at pobox.com
Thu Oct 19 16:59:03 EDT 2006
James> I guess while I'm at it, this thread wouldn't have so much steam
James> were these idioms seemingly unpythonic:
James> "".join(reverse(x))
James> alist[::-1]
James> The latter, while more terse than alist.reversed(), is unnatural
James> and ugly compared to the general elegance of other constructs in
James> python. Were this not the case, beginners and intermediate
James> programmers alike would not have such trouble remembering it.
I've no comment one way or the other on the "".join() idiom. I realize a
lot of folks don't like it. The extended slice notation comes from the
numeric community though where they are probably all former FORTRAN
programmers. I think the concept of start, stop, step (or stride?) is
pretty common there. It also fairly nicely matches the arguments to range()
and extends the list "copy operator" alist[:] in a more-or-less
straightforward fashion. It takes a little getting used to, but it's really
not all that hard to remember once you've seen it a couple times. Besides,
it's not obvious to me that simple sequence slicing would be all that
familiar to the uninitiated.
go-bruins-ly, y'rs,
Skip
More information about the Python-list
mailing list