[Patches] [ python-Patches-661281 ] reverse method for string objects.

noreply@sourceforge.net noreply@sourceforge.net
Thu, 02 Jan 2003 15:25:12 -0800


Patches item #661281, was opened at 2003-01-02 21:06
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=661281&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Wojtek Walczak (gminick)
Assigned to: Nobody/Anonymous (nobody)
Summary: reverse method for string objects.

Initial Comment:
Well, in python 2.3a1 you can reverse a string in dozens of ways, for example:
>>> a = 'string'
>>> a[::-1]
'gnirts'
>>> reduce(lambda x,y: y+x, a)
'gnirts'
>>> b = list(a)
>>> b.reverse()
>>> "".join(b)
'gnirts'
but there's no simple method as function reverse() in plenty of languages. That patch changes that situation by adding reverse method to Objects/stringobject.c
Tested on Linux 2.4.5 with Python2.3alpha1 with i586 platform.
Feel free to improve that or throw it away :)

----------------------------------------------------------------------

>Comment By: Martin v. Löwis (loewis)
Date: 2003-01-03 00:25

Message:
Logged In: YES 
user_id=21627

-1. How often do you need to reverse a string, outside
assignments for programming course? For the latter purpose,
it would actually hurt if Python provided a method for that.

What other languages have builtin reversal of strings?

In addition, your patch is wrong: it leaks len bytes per call.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=661281&group_id=5470