Re: Comparing strings from the back?

2012-09-18 Thread Steven D'Aprano
On Tue, 18 Sep 2012 12:17:40 -0400, Dwight Hutto wrote: > You can call me David. I go by my middle name. If you want to be known as David, why do you give your name as Dwight? In your email client or newsreader, set your name as David and attributions will be to David, and people will know to c

Re: Comparing strings from the back?

2012-09-18 Thread Mark Lawrence
On 18/09/2012 21:40, Dwight Hutto wrote: You're most often going to be addressed by the name that's given in your post headers. In this case "David" has been reduced to an initial, and is visible only in your email address, whereas "Dwight" My sig says David, but it was just to let him know he

Re: Comparing strings from the back?

2012-09-18 Thread Dwight Hutto
> You're most often going to be addressed by the name that's given in > your post headers. In this case "David" has been reduced to an > initial, and is visible only in your email address, whereas "Dwight" My sig says David, but it was just to let him know he can call me by my used name. -- Bes

Re: Comparing strings from the back?

2012-09-18 Thread Chris Angelico
On Wed, Sep 19, 2012 at 2:17 AM, Dwight Hutto wrote: >> >> You're right, my apologies. Dwight Hutto is the one I plonked. > You can call me David. I go by my middle name. You're most often going to be addressed by the name that's given in your post headers. In this case "David" has been reduced

Re: Comparing strings from the back?

2012-09-18 Thread Dwight Hutto
> > You're right, my apologies. Dwight Hutto is the one I plonked. You can call me David. I go by my middle name. And it seem to me I made some valid points about a few simple trimming of postings, that didn't seem necessary in the context of a small quick conversation. -- http://mail.python.org

Re: Comparing strings from the back?

2012-09-18 Thread Dwight Hutto
>>> sufficient context, you've left me feeling puzzled. Is there a guideline for >>> this in basic netiquette? >> www.woodgate.org/FAQs/netiquette.html -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-18 Thread Dwight Hutto
On Tue, Sep 18, 2012 at 11:12 AM, Ethan Furman wrote: > Neil Hodgson wrote: >> >> Ethan Furman: >>> >>> *plonk* >> >> >>I can't work out who you are plonking. While more than one of the >> posters on this thread seem worthy of a good plonk, by not including >> sufficient context, you've left m

Re: Comparing strings from the back?

2012-09-18 Thread Ethan Furman
Neil Hodgson wrote: Ethan Furman: *plonk* I can't work out who you are plonking. While more than one of the posters on this thread seem worthy of a good plonk, by not including sufficient context, you've left me feeling puzzled. Is there a guideline for this in basic netiquette? You're

Re: Comparing strings from the back?

2012-09-17 Thread Neil Hodgson
Ethan Furman: *plonk* I can't work out who you are plonking. While more than one of the posters on this thread seem worthy of a good plonk, by not including sufficient context, you've left me feeling puzzled. Is there a guideline for this in basic netiquette? Neil -- http://mail.pyt

Re: Comparing strings from the back?

2012-09-17 Thread Ethan Furman
*plonk* -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-16 Thread alex23
On Sep 17, 2:05 pm, Chris Angelico wrote: > I would hate to see people leaned > hard on to make their speech entirely politically correct. Use common > sense, on both sides. Don't be offensive, and don't be offended. While I would like to agree, this would require there to be no power disparities

Re: Comparing strings from the back?

2012-09-16 Thread Chris Angelico
On Mon, Sep 17, 2012 at 11:11 AM, alex23 wrote: > On Sep 15, 1:10 pm, Dwight Hutto wrote: >> On Fri, Sep 14, 2012 at 6:43 PM, Prasad, Ramit >> > Since I was unsure myself if you were trying to be offensive or racist, >> > I would disagree with "everyone can know it wasn't meant as racist". >> >>

Re: Comparing strings from the back?

2012-09-16 Thread alex23
On Sep 15, 1:10 pm, Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 6:43 PM, Prasad, Ramit > > Since I was unsure myself if you were trying to be offensive or racist, > > I would disagree with "everyone can know it wasn't meant as racist". > > If you're unsure if it was racist, you should err on the

Re: Comparing strings from the back?

2012-09-14 Thread Dwight Hutto
On Fri, Sep 14, 2012 at 6:43 PM, Prasad, Ramit wrote: > Dwight Hutto wrote: >> On Fri, Sep 14, 2012 at 4:20 AM, alex2find-work-home/3 >> wrote: >> > On Sep 14, 6:04 pm, Dwight Hutto wrote: >> >> > Using foreign names derogatively is a common tactic of the racist. >> >> >> >> Not really. But nic

Re: Comparing strings from the back?

2012-09-14 Thread Steve Howell
On Sep 6, 4:04 am, Oscar Benjamin wrote: > On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > > For random strings (as defined below), the average compare time is > > effectively unrelated to the size of the string, once the size > passes > > some point. > > Define random string as being a s

RE: Comparing strings from the back?

2012-09-14 Thread Prasad, Ramit
Dwight Hutto wrote: > On Fri, Sep 14, 2012 at 4:20 AM, alex23 wrote: > > On Sep 14, 6:04 pm, Dwight Hutto wrote: > >> > Using foreign names derogatively is a common tactic of the racist. > >> > >> Not really. But nice spin on my pun to make me look bad. > > > > It actually *is* common behaviour o

RE: Comparing strings from the back?

2012-09-14 Thread Prasad, Ramit
Dwight Hutto wrote: > On Thu, Sep 13, 2012 at 5:17 PM, Mark Lawrence > wrote: > > On 13/09/2012 21:34, Joshua Landau wrote: > >> > >> On 13 September 2012 20:53, Mark Lawrence > wrote:acci sequence > >> > >>> On 13/09/2012 19:39, Prasad, Ramit wrote: > >>> > Dwight Hutto wrote: > >

Re: Comparing strings from the back?

2012-09-14 Thread Dwight Hutto
[snip] > Please don't feed the trolls. You're down here under the bridge with the rest of us trolls too, Steven. 24/7 -- Best Regards, David Hutto CEO: http://www.hitwebdevelopment.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-14 Thread Dwight Hutto
> I'd recommend reading up on white privilege but I'm pretty sure it'd > be a wasted suggestion. Not really, I tend to like interdisciplinary study. But I'm a little of everything if you like Darwin. > >> >> It's similar to if I said, this is real 'queer' of you to do ya big >> >> pansy, and next

Re: Comparing strings from the back?

2012-09-14 Thread alex23
On Sep 14, 6:53 pm, Dwight Hutto wrote: > Not if there name is ramit. What if your name was john? I'd say I'll > be right back, I have to go take a crap on the john. It's a joke about > a name, not where it originates. I'd recommend reading up on white privilege but I'm pretty sure it'd be a wast

Re: Comparing strings from the back?

2012-09-14 Thread Steven D'Aprano
On Fri, 14 Sep 2012 01:20:53 -0700, alex23 wrote: > On Sep 14, 6:04 pm, Dwight Hutto wrote: [snip] Please don't feed the trolls. -- Steven -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-14 Thread Dwight Hutto
On Fri, Sep 14, 2012 at 4:20 AM, alex23 wrote: > On Sep 14, 6:04 pm, Dwight Hutto wrote: >> > Using foreign names derogatively is a common tactic of the racist. >> >> Not really. But nice spin on my pun to make me look bad. > > It actually *is* common behaviour of racists. > Not if there name is

Re: Comparing strings from the back?

2012-09-14 Thread alex23
On Sep 14, 6:04 pm, Dwight Hutto wrote: > > Using foreign names derogatively is a common tactic of the racist. > > Not really. But nice spin on my pun to make me look bad. It actually *is* common behaviour of racists. > It's similar to if I said, this is real 'queer' of you to do ya big > pansy,

Re: Comparing strings from the back?

2012-09-14 Thread Dwight Hutto
>> I think you're referring to a play on words(ramit). > > Using foreign names derogatively is a common tactic of the racist. Not really. But nice spin on my pun to make me look bad. Keep trying, and maybe you'll come up with an insult/ propaganda that's less obvious to the viewer that you're a l

Re: Comparing strings from the back?

2012-09-13 Thread alex23
On Sep 14, 3:39 pm, Dwight Hutto wrote: > Please explain any logic whatsoever that would give you that conclusion. Well, this: > I think you're referring to a play on words(ramit). Using foreign names derogatively is a common tactic of the racist. > Ain't I so punny. Not really, no. -- http:

Re: Comparing strings from the back?

2012-09-13 Thread Dwight Hutto
On Fri, Sep 14, 2012 at 12:54 AM, alex23 wrote: > On Sep 14, 2:46 pm, Dwight Hutto wrote: >> For telling him to ramit into his head that you should read the OP? > > Yes. I'm not sure if it was intentionally racist, but you come across > as a bit of a dwight supremacist. Please explain any logic

Re: Comparing strings from the back?

2012-09-13 Thread alex23
On Sep 14, 2:46 pm, Dwight Hutto wrote: > For telling him to ramit into his head that you should read the OP? Yes. I'm not sure if it was intentionally racist, but you come across as a bit of a dwight supremacist. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-13 Thread Dwight Hutto
On Thu, Sep 13, 2012 at 11:48 PM, alex23 wrote: > On Sep 14, 5:37 am, Dwight Hutto wrote: >> Why don't take the time to read the OP, and ramit in your head? > > Please, don't be a dick. > > For telling him to ramit into his head that you should read the OP? -- Best Regards, David Hutto CEO:

Re: Comparing strings from the back?

2012-09-13 Thread Chris Angelico
On Fri, Sep 14, 2012 at 1:39 PM, Steven D'Aprano wrote: > You're assuming that people read your posts immediately after they read > the post you replied to. Always imagine that your reply will be read a > week after the post you replied to. And a week is extremely generous too; these posts get ar

Re: Comparing strings from the back?

2012-09-13 Thread alex23
On Sep 14, 5:37 am, Dwight Hutto wrote: > Why don't take the time to read the OP, and ramit in your head? Please, don't be a dick. -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-13 Thread Steven D'Aprano
On Thu, 13 Sep 2012 17:06:23 -0400, Dwight Hutto wrote: > Then there is the problem of people saying you posted too much of the > context, or not inline with the OP, just at the end, or top posting. The solution to "you quoted too much unnecessary verbiage" is not "quote nothing". It is quote on

Re: Comparing strings from the back?

2012-09-13 Thread Dwight Hutto
On Thu, Sep 13, 2012 at 5:17 PM, Mark Lawrence wrote: > On 13/09/2012 21:34, Joshua Landau wrote: >> >> On 13 September 2012 20:53, Mark Lawrence >> wrote:acci sequence >> >>> On 13/09/2012 19:39, Prasad, Ramit wrote: >>> Dwight Hutto wrote: > Why don' you just time it,eit lops thr

Re: Comparing strings from the back?

2012-09-13 Thread Mark Lawrence
On 13/09/2012 21:34, Joshua Landau wrote: On 13 September 2012 20:53, Mark Lawrence wrote: On 13/09/2012 19:39, Prasad, Ramit wrote: Dwight Hutto wrote: Why don' you just time it,eit lops through incrementing thmax input/ What? Without context I have no idea what this means. You're

Re: Comparing strings from the back?

2012-09-13 Thread Dwight Hutto
On Thu, Sep 13, 2012 at 4:34 PM, Joshua Landau wrote: > On 13 September 2012 20:53, Mark Lawrence wrote: >> >> On 13/09/2012 19:39, Prasad, Ramit wrote: >>> >>> Dwight Hutto wrote: Why don' you just time it,eit lops through incrementing thmax input/ >>> >>> >>> What? Without context I h

Re: Comparing strings from the back?

2012-09-13 Thread Joshua Landau
On 13 September 2012 20:53, Mark Lawrence wrote: > On 13/09/2012 19:39, Prasad, Ramit wrote: > >> Dwight Hutto wrote: >> >>> Why don' you just time it,eit lops through incrementing thmax input/ >>> >> >> What? Without context I have no idea what this means. >> > > You're wasting your time, I've

Re: Comparing strings from the back?

2012-09-13 Thread Mark Lawrence
On 13/09/2012 19:39, Prasad, Ramit wrote: Dwight Hutto wrote: Why don' you just time it,eit lops through incrementing thmax input/ What? Without context I have no idea what this means. Ramit You're wasting your time, I've been described as a jackass for having the audacity to ask for con

Re: Comparing strings from the back?

2012-09-13 Thread Dwight Hutto
On Thu, Sep 13, 2012 at 2:39 PM, Prasad, Ramit wrote: > Dwight Hutto wrote: >> Why don' you just time it,eit lops through incrementing thmax input/ > > What? Without context I have no idea what this means. > > > Ramit Why don't you read the OP: Let's assume you're testing two strings for equal

RE: Comparing strings from the back?

2012-09-13 Thread Prasad, Ramit
Dwight Hutto wrote: > Why don' you just time it,eit lops through incrementing thmax input/ What? Without context I have no idea what this means. Ramit -- This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities,

Re: Comparing strings from the back?

2012-09-11 Thread Terry Reedy
On 9/11/2012 6:40 AM, Oscar Benjamin wrote: On 11 September 2012 10:51, Duncan Booth mailto:duncan.booth@invalid.invalid>> wrote: Oscar Benjamin mailto:oscar.j.benja...@gmail.com>> wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare >> if they are equal.

Re: Comparing strings from the back?

2012-09-11 Thread Oscar Benjamin
On 11 September 2012 10:51, Duncan Booth wrote: > Oscar Benjamin wrote: > > >> What interning buys you is that "s == t" is an O(1) pointer compare > >> if they are equal. But if s and t differ in the last character, > >> __eq__ will still inspect every character. There is no way to tell > >> Pyth

Re: Comparing strings from the back?

2012-09-11 Thread Duncan Booth
Oscar Benjamin wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare >> if they are equal. But if s and t differ in the last character, >> __eq__ will still inspect every character. There is no way to tell >> Python "all strings are interned, if s is not t then s != t as w

Re: Comparing strings from the back?

2012-09-11 Thread Duncan Booth
Steven D'Aprano wrote: > But for the record, in principle string comparisons *could* be the > bottleneck. Example: you have 1 strings, which are each created > once and stored in a list. Then you iterate over the list, comparing > every string against every other string. And due to some weir

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dan Goodman wrote: > On 10/09/2012 18:07, Dan Goodman wrote: >> On 04/09/2012 03:54, Roy Smith wrote: >>> Let's assume you're testing two strings for equality. You've already >>> done the obvious quick tests (i.e they're the same length), and you're >>> down to the O(n) part of com

Re: Comparing strings from the back?

2012-09-10 Thread Dan Goodman
On 10/09/2012 18:07, Dan Goodman wrote: On 04/09/2012 03:54, Roy Smith wrote: Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering if it migh

Re: Comparing strings from the back?

2012-09-10 Thread Dan Goodman
On 10/09/2012 18:33, Oscar Benjamin wrote: Computing the hash always requires iterating over all characters in the string so is best case O(N) where string comparison is best case (and often average case) O(1). Yep, but you already have O(N) costs just creating the strings in the first place,

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Dan Goodman wrote: > On 04/09/2012 03:54, Roy Smith wrote: >> Let's assume you're testing two strings for equality. You've already >> done the obvious quick tests (i.e they're the same length), and you're >> down to the O(n) part of comparing every character. >> >> I'm wondering if

Re: Comparing strings from the back?

2012-09-10 Thread Dan Goodman
On 04/09/2012 03:54, Roy Smith wrote: Let's assume you're testing two strings for equality. You've already done the obvious quick tests (i.e they're the same length), and you're down to the O(n) part of comparing every character. I'm wondering if it might be faster to start at the ends of the s

Re: Comparing strings from the back?

2012-09-10 Thread Chris Angelico
On Tue, Sep 11, 2012 at 12:43 AM, Oscar Benjamin wrote: > On 2012-09-10, Oscar Benjamin wrote: >> I haven't looked at the source but my understanding was precisely that there >> is an intern() bit and that not only the builtins module but all the literals >> in any byte-compiled module are intern

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Oscar Benjamin wrote: > On 2012-09-10, Chris Angelico wrote: >> On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin >> wrote: >>> On 2012-09-10, Steven D'Aprano wrote: What interning buys you is that "s == t" is an O(1) pointer compare if they are equal. But if s and t diff

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Chris Angelico wrote: > On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin > wrote: >> On 2012-09-10, Steven D'Aprano wrote: >>> What interning buys you is that "s == t" is an O(1) pointer compare if >>> they are equal. But if s and t differ in the last character, __eq__ will >>> sti

Re: Comparing strings from the back?

2012-09-10 Thread Chris Angelico
On Tue, Sep 11, 2012 at 12:06 AM, Oscar Benjamin wrote: > On 2012-09-10, Steven D'Aprano wrote: >> What interning buys you is that "s == t" is an O(1) pointer compare if >> they are equal. But if s and t differ in the last character, __eq__ will >> still inspect every character. There is no way t

Re: Comparing strings from the back?

2012-09-10 Thread Oscar Benjamin
On 2012-09-10, Steven D'Aprano wrote: > On Mon, 10 Sep 2012 08:59:37 +, Duncan Booth wrote: > >> Gelonida N wrote: >> >> so at the expense of a single dictionary >> insertion when the string is created you can get guaranteed O(1) on all >> the comparisons. > > What interning buys you is that

Re: Comparing strings from the back?

2012-09-10 Thread Steven D'Aprano
On Mon, 10 Sep 2012 08:59:37 +, Duncan Booth wrote: > Gelonida N wrote: > >> On 09/07/2012 06:06 AM, Steven D'Aprano wrote: >>> On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: >>> >>> >>> Also of some interest is the best case: O(1) for unequal strings (they >>> differ at the first cha

Re: Comparing strings from the back?

2012-09-10 Thread Duncan Booth
Gelonida N wrote: > On 09/07/2012 06:06 AM, Steven D'Aprano wrote: >> On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: >> >> >> Also of some interest is the best case: O(1) for unequal strings (they >> differ at the first character) and O(N) for equal strings. > > The worst case is O(N) or

Re: Comparing strings from the back?

2012-09-08 Thread Gelonida N
On 09/07/2012 06:06 AM, Steven D'Aprano wrote: On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: Also of some interest is the best case: O(1) for unequal strings (they differ at the first character) and O(N) for equal strings. The worst case is O(N) or N characters the average case is O(1

Re: Comparing strings from the back?

2012-09-08 Thread Gelonida N
On 09/06/2012 10:33 AM, Steven D'Aprano wrote: On Wed, 05 Sep 2012 22:47:14 +, Oscar Benjamin wrote: I may have been overly-conservative earlier when I said that on average string equality has to compare half the characters. I thought I had remembered that from a computer science textbook, b

Re: Comparing strings from the back?

2012-09-08 Thread Oscar Benjamin
On 2012-09-08, Steven D'Aprano wrote: > On Fri, 07 Sep 2012 19:10:16 +, Oscar Benjamin wrote: > >> On 2012-09-07, Steven D'Aprano >> wrote: >> >> >> Would you say, then, that dict insertion is O(N)? > > Pedantically, yes. > > But since we're allowed to state (or even imply *wink*) whatever

Re: Comparing strings from the back?

2012-09-07 Thread Dwight Hutto
Why don' you just time it,eit lops through incrementing thmax input/ -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopment.com* -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-07 Thread Steven D'Aprano
On Fri, 07 Sep 2012 19:10:16 +, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano > wrote: >> >> >> After further thought, and giving consideration to the arguments given >> by people here, I'm now satisfied to say that for equal-length strings, >> string equality is best described as O

Re: Comparing strings from the back?

2012-09-07 Thread Dwight Hutto
On Fri, Sep 7, 2012 at 5:59 PM, Dwight Hutto wrote: > With unequal strings/lists to match, it would seem that one would regex > through the larger string/list with the shorter string, and piece by piece > begin to match for partial percentage matches in relation to the longer > iterative item. >

Re: Comparing strings from the back?

2012-09-07 Thread Dwight Hutto
With unequal strings/lists to match, it would seem that one would regex through the larger string/list with the shorter string, and piece by piece begin to match for partial percentage matches in relation to the longer iterative item. -- Best Regards, David Hutto *CEO:* *http://www.hitwebdevelopm

Re: Comparing strings from the back?

2012-09-07 Thread Oscar Benjamin
On 2012-09-07, Oscar Benjamin wrote: > On 2012-09-07, Steven D'Aprano wrote: >> > > Since string comparison is only useful if the strings can be equal or unequal, > the average case depends on how often they are equal/unequal as well as the > average complexity of both. For random strings the fr

Re: Comparing strings from the back?

2012-09-07 Thread Oscar Benjamin
On 2012-09-07, Steven D'Aprano wrote: > > > After further thought, and giving consideration to the arguments given by > people here, I'm now satisfied to say that for equal-length strings, > string equality is best described as O(N). > > 1) If the strings are equal, a == b will always compare a

Re: Comparing strings from the back?

2012-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: > On 09/06/2012 04:33 AM, Steven D'Aprano wrote: >> >> >> I may have been overly-conservative earlier when I said that on average >> string equality has to compare half the characters. I thought I had >> remembered that from a computer science

Re: Comparing strings from the back?

2012-09-06 Thread Steven D'Aprano
On Fri, 07 Sep 2012 00:39:33 +1000, Chris Angelico wrote: > On Thu, Sep 6, 2012 at 11:37 PM, Johannes Bauer > wrote: >> Not in my original post. If you read it again, you will clearly see >> that I was talking about purely random strings. And since you like to >> nitpick, I'll clarify further: I'

Re: Comparing strings from the back?

2012-09-06 Thread Dave Angel
On 09/06/2012 10:42 AM, Johannes Bauer wrote: > On 06.09.2012 16:23, Dave Angel wrote: >> On 09/06/2012 09:43 AM, Johannes Bauer wrote: >>> >>> Yes, worst-case is O(N), best case O(1). Average is O(n log n). >> Can't see how you came up with an average of n log(n). Fourteen minutes >> before you

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 17:36, Johannes Bauer wrote: > "pleasedumpstats" < "" And against a XML-reading C code generator that uses mako: strCmpEq 39670 strCmpLt 2766215 strCmpGt 2744002 strCmpTc 37430821 strCmpCc 14048656 Compared strings: 5549887 Equal: 0.7% Average wordlength: 6.74 chars Average compare

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 16:39, Chris Angelico wrote: > In any case, it'll be far FAR more useful than arguing from > totally random, or random word selection, or anything. > > Who's game? Okay, patched against Python 3.2.3: http://pastebin.com/PRRN53P6 To invoke display of the stats, compare the string "

Re: Comparing strings from the back?

2012-09-06 Thread Chris Angelico
On Thu, Sep 6, 2012 at 11:37 PM, Johannes Bauer wrote: > Not in my original post. If you read it again, you will clearly see that > I was talking about purely random strings. And since you like to > nitpick, I'll clarify further: I'm talking about bitstrings in which > every bit of every character

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 16:23, Dave Angel wrote: > On 09/06/2012 09:43 AM, Johannes Bauer wrote: >> >> Yes, worst-case is O(N), best case O(1). Average is O(n log n). > > Can't see how you came up with an average of n log(n). Fourteen minutes > before you made this post, you demonstrated it was less than

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 15:43, Johannes Bauer wrote: > Wrong, at least for randomized strings (i.e. every character with the > same probability). O(N) is worst-case, O(log N) is correct for > randomized strings. ^^ Here I write the right thing. Then further below... > Yes, worst-case is O(N), best case O(1

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 16:23, Dave Angel wrote: > On 09/06/2012 09:43 AM, Johannes Bauer wrote: >> >> Yes, worst-case is O(N), best case O(1). Average is O(n log n). > > Can't see how you came up with an average of n log(n). Fourteen minutes > before you made this post, you demonstrated it was less than

Re: Comparing strings from the back?

2012-09-06 Thread Dave Angel
On 09/06/2012 09:43 AM, Johannes Bauer wrote: > > Yes, worst-case is O(N), best case O(1). Average is O(n log n). Can't see how you came up with an average of n log(n). Fourteen minutes before you made this post, you demonstrated it was less than 2 for any N. And I previously posted that for a

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 06.09.2012 10:33, Steven D'Aprano wrote: > But you know, it really doesn't make a difference. Equality testing will > *still* be O(N) since the asymptomatic behaviour for sufficiently large > string comparisons will be bounded by O(N). Multiplicative constants > ("half the string" versus "0.

Re: Comparing strings from the back?

2012-09-06 Thread Johannes Bauer
On 05.09.2012 18:24, Steven D'Aprano wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>> where the words typically differ only in

Re: Comparing strings from the back?

2012-09-06 Thread Chris Angelico
n Thu, Sep 6, 2012 at 10:13 PM, Roy Smith wrote: > In article <50485fca$0$29977$c3e8da3$54964...@news.astraweb.com>, > Steven D'Aprano wrote: > >> In any case, the *worst* case for string equality >> testing is certainly O(N) (every character must be looked at), and the >> *best* case is O(1) ob

Re: Comparing strings from the back?

2012-09-06 Thread Roy Smith
In article <50485fca$0$29977$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > In any case, the *worst* case for string equality > testing is certainly O(N) (every character must be looked at), and the > *best* case is O(1) obviously (the first character fails to match). The best

Re: Comparing strings from the back?

2012-09-06 Thread Oscar Benjamin
On Thu, 06 Sep 2012 06:07:38 -0400, Dave Angel wrote: For random strings (as defined below), the average compare time is effectively unrelated to the size of the string, once the size passes some point. Define random string as being a selection from a set of characters, with replacement.

Re: Comparing strings from the back?

2012-09-06 Thread Dave Angel
On 09/06/2012 04:33 AM, Steven D'Aprano wrote: > > > I may have been overly-conservative earlier when I said that on > average string equality has to compare half the characters. I thought > I had remembered that from a computer science textbook, but I can't > find that reference now, so possibly

Re: Comparing strings from the back?

2012-09-06 Thread Steven D'Aprano
On Wed, 05 Sep 2012 22:47:14 +, Oscar Benjamin wrote: > In news.gmane.comp.python.general, you wrote: >> On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: [...] You are making unjustified assumptions about the distribution of letters in the words. This might be a list of long

Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
In news.gmane.comp.python.general, you wrote: > On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: > [...] >>> You are making unjustified assumptions about the distribution of >>> letters in the words. This might be a list of long chemical compounds >>> where the words typically differ only

Re: Comparing strings from the back?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 16:51:10 +0200, Johannes Bauer wrote: [...] >> You are making unjustified assumptions about the distribution of >> letters in the words. This might be a list of long chemical compounds >> where the words typically differ only in their suffix. It might be a >> list of people with

Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Oscar Benjamin wrote: > On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote: >> def count_common(a, b): [sorry for seriously broken implementation] > This function will return 1 if the first character differs. It does not > count the number of common characters but rather the more r

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 16:30, Steven D'Aprano wrote: > Since these are *completely different Ns*, you can't combine them to get > O(N**2 log N) as the overall algorithmic complexity. Doing so is sheer > nonsense. If you state it like this: Yes, you are correct here. > You are making unjustified assumpt

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 04:18, Neil Hodgson wrote: >The memcpy patch was controversial as it broke Adobe Flash which > assumed memcpy was safe like memmove. Adobe Flash was broken before, making an assumption that is not guaranteed by the standard. The patch only showed the problem. Regards, Johannes

Re: Comparing strings from the back?

2012-09-05 Thread Steven D'Aprano
On Wed, 05 Sep 2012 11:43:08 +0200, Johannes Bauer wrote: > On 05.09.2012 11:24, Johannes Bauer wrote: > >> Consider sorting a large dictionary. Sorting is in O(n log(n)), but >> this assumes O(1) comparisons! If the comparison operation itself were >> in O(n), the total sorting complexity would

Re: Comparing strings from the back?

2012-09-05 Thread Oscar Benjamin
On 5 September 2012 10:48, Peter Otten <__pete...@web.de> wrote: > Chris Angelico wrote: > > > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote: > >> comparing every pair in a sample of 1000 8-char words > >> taken from '/usr/share/dict/words' > >> > >> head > >> 1: 477222

Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Chris Angelico wrote: > On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote: >> comparing every pair in a sample of 1000 8-char words >> taken from '/usr/share/dict/words' >> >> head >> 1: 477222 >> 2: 18870 ** >> ...

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 05.09.2012 11:24, Johannes Bauer wrote: > Consider sorting a large dictionary. Sorting is in O(n log(n)), but this > assumes O(1) comparisons! If the comparison operation itself were in > O(n), the total sorting complexity would be O(n^2 log(n)), which is > definitely false. Most comparisons wi

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 04.09.2012 23:59, Chris Angelico wrote: >> n = (256 / 255) * (1 - 256 ^ (-c)) >> >> where n is the average number of character comparisons and c. The >> rationale as follows: The first character has to be compared in any >> case. The second with a probability of 1/256, the third with 1/(256^2)

Re: Comparing strings from the back?

2012-09-05 Thread Johannes Bauer
On 04.09.2012 20:07, Steven D'Aprano wrote: > A reasonable, conservative assumption is to calculate the largest > possible value of the average for random strings. That largest value > occurs when the alphabet is as small as possible, namely two characters. > In practice, strings come from a lar

Re: Comparing strings from the back?

2012-09-05 Thread Andrew Artajos
a random idea: you could compare strings by their hashes.. print hash("randomstring") == hash("randomstring") print hash("randomstring") == hash("randoMstring") -- -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-05 Thread Chris Angelico
On Wed, Sep 5, 2012 at 6:29 PM, Peter Otten <__pete...@web.de> wrote: > comparing every pair in a sample of 1000 8-char words > taken from '/usr/share/dict/words' > > head > 1: 477222 > 2: 18870 ** > ... Not understanding this. What are

Re: Comparing strings from the back?

2012-09-05 Thread Peter Otten
Roy Smith wrote: > There's been a bunch of threads lately about string implementations, and > that got me thinking (which is often a dangerous thing). > > Let's assume you're testing two strings for equality. You've already > done the obvious quick tests (i.e they're the same length), and you're

Re: Comparing strings from the back?

2012-09-04 Thread Roy Smith
In article <-9cdnaqjtk6nktvnnz2dnuvz_gedn...@westnet.com.au>, Neil Hodgson wrote: > The memcpy patch was controversial as it broke Adobe Flash An added benefit! -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing strings from the back?

2012-09-04 Thread MRAB
On 05/09/2012 03:18, Neil Hodgson wrote: Roy Smith: I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. Most people write loops that go forwards. This

Re: Comparing strings from the back?

2012-09-04 Thread Neil Hodgson
Roy Smith: I'm wondering if it might be faster to start at the ends of the strings instead of at the beginning? If the strings are indeed equal, it's the same amount of work starting from either end. Most people write loops that go forwards. This leads to the processor designers prioritiz

Re: Comparing strings from the back?

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 22:59, Chris Angelico wrote: > On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer > wrote: > > How do you arrive at that conclusion? When comparing two random strings, > > I just derived > > > > n = (256 / 255) * (1 - 256 ^ (-c)) > > > > where n is the average number of character

Re: Comparing strings from the back?

2012-09-04 Thread Chris Angelico
On Wed, Sep 5, 2012 at 2:32 AM, Johannes Bauer wrote: > How do you arrive at that conclusion? When comparing two random strings, > I just derived > > n = (256 / 255) * (1 - 256 ^ (-c)) > > where n is the average number of character comparisons and c. The > rationale as follows: The first character

Re: Comparing strings from the back?

2012-09-04 Thread Oscar Benjamin
On 4 September 2012 19:07, Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Tue, 04 Sep 2012 18:32:57 +0200, Johannes Bauer wrote: > > > On 04.09.2012 04:17, Steven D'Aprano wrote: > > > >> On average, string equality needs to check half the characters in the > >> string. > > >

  1   2   >