Python Love :)

Peter Otten __peter__ at web.de
Mon Mar 13 13:21:42 EST 2006


Paul Rubin wrote:

> "gregarican" <greg.kujawa at gmail.com> writes:
>> > reversed(a_string)     (python)
>> 
>> Which version of Python offers this function? It doesn't seem to be
>> available in the 2.3 version I have installed...
> 
> I think it's new in 2.4.

Needs a little help, though:

>>> print reversed("abba")
<reversed object at 0x4029454c>

>>> class Str(str):
...     def __reversed__(self):
...             return self[::-1]
...
>>> reversed(Str("abba"))
'abba'

Now if only I had picked a better example :-)

Peter



More information about the Python-list mailing list