Re: invert or reverse a string... warning this is a rant

2006-10-23 Thread DaveM
On Thu, 19 Oct 2006 20:07:27 -0400, Brad [EMAIL PROTECTED] wrote: It has been my experience that Python has discouraging forums with someone always calling someone else an idiot or telling them they are awful in some way. I love Python, but the community is way too negative, uptight and

Re: invert or reverse a string... warning this is a rant

2006-10-21 Thread Ron Adam
Steven D'Aprano wrote: On Thu, 19 Oct 2006 20:07:27 -0400, Brad wrote: Steven D'Aprano wrote: Gah!!! That's *awful* in so many ways. Thanks... I'm used to hearing encouragement like that. After a while you begin to believe that everything you do will be awful, so why even bother trying?

Re: invert or reverse a string... warning this is a rant

2006-10-21 Thread Steven D'Aprano
On Fri, 20 Oct 2006 16:17:09 +0200, Fredrik Lundh wrote: Tim N. van der Leeuw wrote: In practice, the short-term fix would be to add a __str__ method to the 'reversed' object so what should str(reversed(range(10))) do ? The same as str(range(9, -1, -1)) perhaps? I notice that

Re: invert or reverse a string... warning this is a rant

2006-10-21 Thread Steven D'Aprano
On Sat, 21 Oct 2006 01:58:33 -0500, Ron Adam wrote: [You said from an earlier post...] (That's a complaint I have about the dis module -- it prints its results, instead of returning them as a string. That makes it hard to capture the output for further analysis.) I have a rewritten

Re: invert or reverse a string... warning this is a rant

2006-10-21 Thread Ron Adam
Steven D'Aprano wrote: On Sat, 21 Oct 2006 01:58:33 -0500, Ron Adam wrote: [You said from an earlier post...] (That's a complaint I have about the dis module -- it prints its results, instead of returning them as a string. That makes it hard to capture the output for further analysis.) I

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Hendrik van Rooyen
Fredrik Lundh [EMAIL PROTECTED]wrote: 8--- 'a man a plan a canal panama' is not a palindrome ? not if spaces count - able was I ere I saw elba - is one - but its a tougher test... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Hendrik van Rooyen
Brad [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: Gah!!! That's *awful* in so many ways. Thanks... I'm used to hearing encouragement like that. After a while you begin to believe that everything you do will be awful, so why even bother trying? rant It has been my experience that

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Simon Forman
rick wrote: ... see that the sequence is reversed. Backwards is pure, simple and easy. This is not so in Python and it should be. foo[::-1] isn't pure, simple and easy? It derives cleanly from the slice notation, it does exactly what you want, and it even works with lists and tuples and any

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread I V
On Fri, 20 Oct 2006 09:04:07 +1000, Steven D'Aprano wrote: I agree -- the reversed() function appears to be an obvious case of purity overriding practicality :( str(reversed(some string)) 'reversed object at 0xb7edca4c' repr(reversed(some string)) 'reversed object at 0xb7edca4c' This

RE: invert or reverse a string... warning this is a rant

2006-10-20 Thread Demel, Jeff
Paul wrote: .join(sum(map(list,zip(s,s[len(s)/2:])),[])) perhaps? Not quite as elegant as a string.shuffle would be, am I right? -Jeff This email is intended only for the individual or entity to which it is addressed. This email may contain information that is privileged, confidential or

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Kay Schluehr
The Ruby approach makes sense to me as a human being. http://happyfuncog.blogspot.com/2006/09/confessions-of-pseudo-misanthrope.html The Python approach is not easy for me (as a human being) to remember. I always thought we Pythonistas are already idiots but whenever I meet a Rubist it ( the

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Fredrik Lundh
Brad [EMAIL PROTECTED] wrote: Do you have children? How would your child feel if he brought you something he had made and you then told him it was awful in *sooo* many ways. If you're arguing that everything a child does and says should be rewarded, I seriously doubt that you have any. (on

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Fredrik Lundh
Hendrik van Rooyen wrote: 'a man a plan a canal panama' is not a palindrome not if spaces count - which they do if you rely on a single reverse operation (my point was that it takes a bit more work than that to check for a palindrome). /F --

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread rick
Fredrik Lundh wrote: Brad [EMAIL PROTECTED] wrote: Do you have children? How would your child feel if he brought you something he had made and you then told him it was awful in *sooo* many ways. If you're arguing that everything a child does and says should be rewarded... I'm not

RE: invert or reverse a string... warning this is a rant

2006-10-20 Thread Duncan Booth
Demel, Jeff [EMAIL PROTECTED] wrote: I've been programming professionally for over 10 years, and have never once needed to reverse a string. Maybe it's a lack of imagination on my part, but I can't think of a single instance this might be necessary. I did want to reverse some strings once,

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Tim N. van der Leeuw
I V wrote: On Fri, 20 Oct 2006 09:04:07 +1000, Steven D'Aprano wrote: I agree -- the reversed() function appears to be an obvious case of purity overriding practicality :( str(reversed(some string)) 'reversed object at 0xb7edca4c' repr(reversed(some string)) 'reversed object at

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Fredrik Lundh
Tim N. van der Leeuw wrote: In practice, the short-term fix would be to add a __str__ method to the 'reversed' object so what should str(reversed(range(10))) do ? and perhaps to all iterators too (so that trying to build a string from an iterator would do the obvious thing). all

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Carl Banks
[EMAIL PROTECTED] wrote: 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. Yep. I do a bit of numerical work and the meaning of abc[::-1]

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Carl Banks
Demel, Jeff wrote: I've been programming professionally for over 10 years, and have never once needed to reverse a string. Maybe it's a lack of imagination on my part, but I can't think of a single instance this might be necessary. Say you're using a function from a third-party library that

RE: invert or reverse a string... warning this is a rant

2006-10-20 Thread Demel, Jeff
Demel, Jeff wrote: I've been programming professionally for over 10 years, and have never once needed to reverse a string. Maybe it's a lack of imagination on my part, but I can't think of a single instance this might be necessary. Carl wrote: Say you're using a function from a third-party

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Tim N. van der Leeuw
Fredrik Lundh wrote: Tim N. van der Leeuw wrote: In practice, the short-term fix would be to add a __str__ method to the 'reversed' object so what should str(reversed(range(10))) do ? My idea was that reversed.__str__() would do something like the equivalent of

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread egbert
John Salerno wrote: I'm not steeped enough in daily programming to argue that it isn't necessary, but my question is why do you need to reverse strings? Is it something that happens often enough to warrant a method for it? String reversal comes in handy when you do palindromes. --

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Istvan Albert
Carl Banks wrote: Say you're using a function from a third-party library that finds the first character in a string that meets some requirement. You need to find the last such character. You seem to imply that invoking a function on a reversed input is somehow a generic solution to the

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Istvan Albert
egbert wrote: String reversal comes in handy when you do palindromes. Yes, that's where the big bucks are, the Palindrome Industry. It is the shortsightedness of the Python core developers that keeps the palindrome related functions and algorithms out of the standard library i. --

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread skip
egbert String reversal comes in handy when you do palindromes. Which would by implication make it handy to have in a CS algorithms class and not much else. ;-) Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Simon Brunning
On 20 Oct 2006 09:34:55 -0700, Istvan Albert [EMAIL PROTECTED] wrote: Yes, that's where the big bucks are, the Palindrome Industry. It is the shortsightedness of the Python core developers that keeps the palindrome related functions and algorithms out of the standard library +1 QOTW --

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Carl Banks
Istvan Albert wrote: Carl Banks wrote: Say you're using a function from a third-party library that finds the first character in a string that meets some requirement. You need to find the last such character. You seem to imply that invoking a function on a reversed input is somehow a

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Steven D'Aprano
On Thu, 19 Oct 2006 20:07:27 -0400, Brad wrote: Steven D'Aprano wrote: Gah!!! That's *awful* in so many ways. Thanks... I'm used to hearing encouragement like that. After a while you begin to believe that everything you do will be awful, so why even bother trying? Well obviously I hit

Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread Steven D'Aprano
On Thu, 19 Oct 2006 22:22:34 -0300, Gabriel Genellina wrote: (1) The name is bad. invert is not the same as reverse. Here's an invert: 1/2 = 0.5. Your function falsely claims numbers aren't invertable. Dictionary.com invert = to reverse in position, order, direction, or relationship.

invert or reverse a string... warning this is a rant

2006-10-19 Thread rick
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x[::-1] Ruby: x = 'a_string' # Reverse the string print x.reverse The Ruby approach makes sense to me as a human being. The Python approach is not easy for me (as a human being) to

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread John Salerno
rick wrote: Why can't Python have a reverse() function/method like Ruby? I'm not steeped enough in daily programming to argue that it isn't necessary, but my question is why do you need to reverse strings? Is it something that happens often enough to warrant a method for it? --

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Paul Rubin
rick [EMAIL PROTECTED] writes: Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x[::-1] The Ruby approach makes sense to me as a human being. The Python approach is not easy for me (as a human being) to remember. Can that be

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Fredrik Lundh
rick wrote: The Ruby approach makes sense to me as a human being. do the humans on your planet spend a lot of time reversing strings? it's definitely not a very common thing to do over here. anyway, if you do this a lot, why not define a helper function? def reverse(s): return

RE: invert or reverse a string... warning this is a rant

2006-10-19 Thread Demel, Jeff
John Salerno wrote: 'm not steeped enough in daily programming to argue that it sn't necessary, but my question is why do you need to reverse strings? Is it something that happens often enough to warrant a method for it? I've been programming professionally for over 10 years, and have never

RE: invert or reverse a string... warning this is a rant

2006-10-19 Thread Demel, Jeff
John Salerno wrote: 'm not steeped enough in daily programming to argue that it sn't necessary, but my question is why do you need to reverse strings? Is it something that happens often enough to warrant a method for it? I've been programming professionally for over 10 years, and have never

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Brad
John Salerno wrote: rick wrote: Why can't Python have a reverse() function/method like Ruby? I'm not steeped enough in daily programming to argue that it isn't necessary, but my question is why do you need to reverse strings? Is it something that happens often enough to warrant a method

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Neil Cerutti
On 2006-10-19, Brad [EMAIL PROTECTED] wrote: I'm home for lunch so my email addy is different. No, it doesn't happen very often, but when I need to reverse something (usually a list or a string). I can never remember right of the top of my head how to do so in Python. I always have to Google

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Brad
Fredrik Lundh wrote: rick wrote: The Ruby approach makes sense to me as a human being. do the humans on your planet spend a lot of time reversing strings? it's definitely not a very common thing to do over here. On our planet, we're all dyslexic. We tend to do things 'backwards' so

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Paul McGuire
Demel, Jeff [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] John Salerno wrote: P.S. How about a string.shuffle() method that splits the string in half into two new strings str1 and str2, and then recompiles the string by alternating one character from each str1 and str2 as it goes?

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Tim Chase
P.S. How about a string.shuffle() method that splits the string in half into two new strings str1 and str2, and then recompiles the string by alternating one character from each str1 and str2 as it goes? Like shuffling cards. ;) Well, for a true shuffling of a string, there's a

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Fredrik Lundh
Dennis Lee Bieber wrote: ONE usage... The old intro-to-programming Palindrome detector becomes a very simple assignment given an easy means of reversing a string (vs the expected loop comparing from the ends in to the center) you mean like s = a man a plan a canal panama if list(s)

RE: invert or reverse a string... warning this is a rant

2006-10-19 Thread Demel, Jeff
[EMAIL PROTECTED] wrote: ONE usage... The old intro-to-programming Palindrome detector becomes a very simple assignment given an easy means of reversing a string (vs the expected loop comparing from the ends in to the center) Ok, let me re-phrase: ...[snip]... I've been programming

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread James Stroud
John Salerno wrote: rick wrote: Why can't Python have a reverse() function/method like Ruby? I'm not steeped enough in daily programming to argue that it isn't necessary, but my question is why do you need to reverse strings? It would provide symmetry for reversing any sequence

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread rick
Demel, Jeff wrote: Ok, let me re-phrase: ...[snip]... I've been programming professionally for over 10 years, and have never once needed to reverse a string *or detect a palindrome*. Maybe it's a lack of imagination on my part, but I can't think of a single instance this might be

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Tim Chase
Is this why the applicants I see that are fresh out of college with their shiny new computer science degrees can't seem to code their way out of a wet paper bag? Well, there you go! Apparently, your wet paper bag has no detect a palendrome exit. While you're installing such an egress to

OT--Shuffling, was Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread J. Clifford Dyer
Demel, Jeff wrote: P.S. How about a string.shuffle() method that splits the string in half into two new strings str1 and str2, and then recompiles the string by alternating one character from each str1 and str2 as it goes? Like shuffling cards. ;) Jeff, To my mind that would be the

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread rick
Tim Chase wrote: Well, there you go! Apparently, your wet paper bag has no detect a palendrome exit. While you're installing such an egress to your soggy dead-tree satchel, you could also provide similar write a binary Glad you guys are enjoying this. We're getting off-topic and I think

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Paul Boddie
James Stroud wrote: It would provide symmetry for reversing any sequence (without requiring an iterator). (1,2,3).reversed() 123.reversed() [1,2,3].reversed() That might infuriate those who regard strings as mischievous sequences (ie. things which cause errors because you think you have

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread James Stroud
Paul Boddie wrote: James Stroud wrote: (1,2,3).reversed() 123.reversed() [1,2,3].reversed() I guess Python 2.5 has the reversed method of which you speak. Not that I could find (as methods of any built in sequence type). 2.5 just has the reversed function that returns and iterator and so

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Ron Adam
James Stroud wrote: Of course, I think str.join can operate on iterators, as Paul Rubin suggests: print ''.join(reversed(x)) This latter approach still seems a little clunky, though. James Slices can be named so you could do... reverser = slice(None, None, -1)

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Fredrik Lundh
James Stroud wrote: without requiring an iterator can we perhaps invent some more arbitrary constraints while we're at it? /F -- http://mail.python.org/mailman/listinfo/python-list

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Fredrik Lundh
rick wrote: Well, there you go! Apparently, your wet paper bag has no detect a palendrome exit. While you're installing such an egress to your soggy dead-tree satchel, you could also provide similar write a binary Glad you guys are enjoying this. We're getting off-topic and I think my

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread James Stroud
Fredrik Lundh wrote: James Stroud wrote: without requiring an iterator can we perhaps invent some more arbitrary constraints while we're at it? /F Why does it seem to me that you are confusing convienience with constraint, or are the two equivalent? James -- James Stroud

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Neil Cerutti
On 2006-10-19, Fredrik Lundh [EMAIL PROTECTED] wrote: James Stroud wrote: without requiring an iterator can we perhaps invent some more arbitrary constraints while we're at it? No letter G. I don't like them. They wet their nests. -- Neil Cerutti You only get a once-in-a-lifetime

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread James Stroud
Fredrik Lundh wrote: James Stroud wrote: without requiring an iterator can we perhaps invent some more arbitrary constraints while we're at it? /F I guess while I'm at it, this thread wouldn't have so much steam were these idioms seemingly unpythonic: .join(reverse(x))

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread James Stroud
Neil Cerutti wrote: On 2006-10-19, Fredrik Lundh [EMAIL PROTECTED] wrote: James Stroud wrote: without requiring an iterator can we perhaps invent some more arbitrary constraints while we're at it? No letter G. I don't like them. They wet their nests. The requirement for an iterator

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread skip
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)) Jamesalist[::-1] James The latter, while more terse than alist.reversed(), is unnatural James and ugly compared to

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Steven D'Aprano
On Thu, 19 Oct 2006 12:38:55 -0400, Brad wrote: John Salerno wrote: rick wrote: Why can't Python have a reverse() function/method like Ruby? I'm not steeped enough in daily programming to argue that it isn't necessary, but my question is why do you need to reverse strings? Is it

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: ''.join(list(reversed(some string))) 'gnirts emos' ''.join(reversed('some string')) should work, without building the intermediate list. I generally don't remember the ::-1 syntax so the above would occur to me sooner. --

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Brad
Steven D'Aprano wrote: Gah!!! That's *awful* in so many ways. Thanks... I'm used to hearing encouragement like that. After a while you begin to believe that everything you do will be awful, so why even bother trying? rant It has been my experience that Python has discouraging forums with

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Gabriel Genellina
At Thursday 19/10/2006 21:07, Brad wrote: Gah!!! That's *awful* in so many ways. It has been my experience that Python has discouraging forums with someone always calling someone else an idiot or telling them they are awful in some way. I love Python, but the community is way too negative,

Re: invert or reverse a string... warning this is a rant

2006-10-19 Thread Rainy
Brad wrote: John Salerno wrote: rick wrote: Why can't Python have a reverse() function/method like Ruby? I'm not steeped enough in daily programming to argue that it isn't necessary, but my question is why do you need to reverse strings? Is it something that happens often enough to