[Python-bugs-list] [ python-Feature Requests-494240 ] str.reverse

noreply@sourceforge.net noreply@sourceforge.net
Mon, 04 Nov 2002 18:03:22 -0800


Feature Requests item #494240, was opened at 2001-12-17 11:50
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=494240&group_id=5470

Category: Python Library
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Submitted By: Allan Crooks (amc1)
Assigned to: Nobody/Anonymous (nobody)
Summary: str.reverse

Initial Comment:
The str type should *really* have a reverse 
method. "How do I reverse a string?" crops up too 
often on tutor lists, and there should be a neater way 
to do it other than converting it to a list, reversing 
it, and then joining it...

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

Comment By: michael morrell (mgmorrell)
Date: 2002-11-04 21:03

Message:
Logged In: YES 
user_id=642473

A real life example certainly does exist. A source text file
from the "Online Bible" Hebrew text files are in ascii, but,
are backwards  on each line,
for purpose such as sorting etc. They need to be reversed
for my purposes, often. and then reversed back. I for one
firmly believe you should have a reverse() in python.



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

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-09-30 08:49

Message:
Logged In: YES 
user_id=6380

But reversing a string is such a rare thing to do that it's
not worth extending the language for it.

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

Comment By: Allan Crooks (amc1)
Date: 2002-09-30 04:44

Message:
Logged In: YES 
user_id=39733

> "spam"[::-1]

Well, it's nice to be able to reverse a string easily, but does 
anyone else think that using this syntax to reverse a string is 
somewhat un-Pythonic? "spam".reverse() would at least 
make sense instantly to anyone reading it...

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

Comment By: Allan Crooks (amc1)
Date: 2002-09-30 04:44

Message:
Logged In: YES 
user_id=39733

> "spam"[::-1]

Well, it's nice to be able to reverse a string easily, but does 
anyone else think that using this syntax to reverse a string is 
somewhat un-Pythonic? "spam".reverse() would at least 
make sense instantly to anyone reading it...

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

Comment By: Walter Dörwald (doerwalter)
Date: 2002-09-04 15:45

Message:
Logged In: YES 
user_id=89016

String reversing is possible now via extended slices:

>>> "spam"[::-1]   
'maps'

I guess we can close the request.


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

Comment By: Tim Peters (tim_one)
Date: 2001-12-17 23:57

Message:
Logged In: YES 
user_id=31435

Here's an application of (sub)string reversal in dartboard 
design:

http://www.combinatorics.org/Volume_8/PDF/v8i2r4.pdf

I'd hate to see Python fall behind in the lucrative 
dartboard designer market <bullseye>.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-17 23:22

Message:
Logged In: YES 
user_id=6380

Write a PEP. :-)

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

Comment By: Allan Crooks (amc1)
Date: 2001-12-17 23:17

Message:
Logged In: YES 
user_id=39733

> Show me one real-life application of reversing a string.

Ummm.... easy way to check for palindromes?

> This comes from textbook exercises IMO,
> and doesn't occur in real life.

It may not occur in many serious applications, but there 
have been occasions where I've simply wanted to reverse a 
string just for the fun of it really (or just to check 
quickly what something is backwards).

> Adding the method would reduce the
> utility of the textbook exercise...

Not unless you explicitly said not to use str.reverse... 
You could argue that doing l = list('something'); l.reverse
(); ''.join(l) perhaps is still a bit too easy for a text 
book. Something more appropriate like for loops and ranges 
would be suitable for an exercise.

I dunno, it just seems like it's the sort of method that 
should be part of str, and it doesn't seem like the method 
would be that huge or problematic to implement...

If that doesn't convince you, then at least say you'll 
implement it if I figure out a worthwhile use for it. :))

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-17 11:57

Message:
Logged In: YES 
user_id=6380

Show me one real-life application of reversing a string.
This comes from textbook exercises IMO, and doesn't occur in
real life. Adding the method would reduce the utility of the
textbook exercise...

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

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