palindrome iteration

Jon Clements joncle at
Sat Aug 28 14:57:25 CEST 2010

On Aug 28, 11:55 am, Steven D'Aprano <st... at REMOVE-THIS-> wrote:
> On Sat, 28 Aug 2010 09:22:13 +0300, Jussi Piitulainen wrote:
> > Terry Reedy writes:
> >> On 8/27/2010 3:43 PM, Jussi Piitulainen wrote:
> >> > Dave Angel writes:

> Not everything needs to be a built-in method. There is already a standard
> way to spell "reverse a string":
> astring[::-1]
> If you don't like that, you can do this:
> ''.join(reversed(astring))

I've had to debug code that assumed str(reversed('abc')) == 'cba'
>>> str(reversed('abc'))
'<reversed object at 0xa66f78c>'

So, a str doesn't "construct" like tuple/'s a call to
It's designated as a "friendly print out" (that's my phrasing).

>>> list('abc')
['a', 'b', 'c']

I s'pose str is special (2.6) in some way, but it doesn't parallel the
other builtins.

[Not at Terry / Steve intended -- just most relevant post to respond


More information about the Python-list mailing list