Re: While we're talking about annoyances

2007-05-02 Thread Alex Martelli
Michael Hoffman <[EMAIL PROTECTED]> wrote: > Steven D'Aprano wrote: > > On Wed, 02 May 2007 06:10:54 +, Tim Roberts wrote: > > >> I've tended to favor the "Schwarzian transform" (decorate-sort-undecorate) > >> because of that. > > > > That's what the key= argument does. cmp= is slow because

Re: While we're talking about annoyances

2007-05-02 Thread Michael Hoffman
Steven D'Aprano wrote: > On Wed, 02 May 2007 06:10:54 +, Tim Roberts wrote: >> I've tended to favor the "Schwarzian transform" (decorate-sort-undecorate) >> because of that. > > That's what the key= argument does. cmp= is slow because the comparison > function is called for EVERY comparison.

Re: While we're talking about annoyances

2007-05-01 Thread Steven D'Aprano
On Wed, 02 May 2007 06:10:54 +, Tim Roberts wrote: > Michael Hoffman <[EMAIL PROTECTED]> wrote: >> >>Hint: if you find yourself using a decorate-sort-undecorate pattern, >>sorted(key=func) or sequence.sort(key=func) might be a better idea. > > Is it? I thought I remember reading on this ver

Re: While we're talking about annoyances

2007-05-01 Thread Tim Roberts
Michael Hoffman <[EMAIL PROTECTED]> wrote: > >Hint: if you find yourself using a decorate-sort-undecorate pattern, >sorted(key=func) or sequence.sort(key=func) might be a better idea. Is it? I thought I remember reading on this very list some years ago that the performance of sequence.sort becam

Re: While we're talking about annoyances

2007-05-01 Thread Arnaud Delobelle
On Apr 30, 3:51 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > Michael Hoffman <[EMAIL PROTECTED]> wrote: > >... > > > >> Well, counting the index() function that is called in both cases, the > > >> original rank() had one sort, but my version has two sorts. > > > > That doesn't affet the big-O

Re: While we're talking about annoyances

2007-04-30 Thread Alex Martelli
Michael Hoffman <[EMAIL PROTECTED]> wrote: ... > >> Well, counting the index() function that is called in both cases, the > >> original rank() had one sort, but my version has two sorts. > > > > That doesn't affet the big-O behavior -- O(N log N) holds whether you > > have one sort, or three, o

Re: While we're talking about annoyances

2007-04-30 Thread Michael Hoffman
Alex Martelli wrote: > Michael Hoffman <[EMAIL PROTECTED]> wrote: > >> Alex Martelli wrote: >>> Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >>>... >>> decorated.sort() >>>... > def index(sequence): > return sorted(range(len(sequence)), key=sequence.__getitem__) >>>

Re: While we're talking about annoyances

2007-04-30 Thread Arnaud Delobelle
On Apr 30, 2:50 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > >... > > > > >> decorated.sort() >... > > > def index(sequence): > > > return sorted(range(len(sequence)), key=sequence.__getitem__) >... > > But really these two versio

Re: While we're talking about annoyances

2007-04-29 Thread Alex Martelli
Michael Hoffman <[EMAIL PROTECTED]> wrote: > Alex Martelli wrote: > > Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > >... > > decorated.sort() > >... > >>> def index(sequence): > >>> return sorted(range(len(sequence)), key=sequence.__getitem__) > >... > >> But really these

Re: While we're talking about annoyances

2007-04-29 Thread Michael Hoffman
Alex Martelli wrote: > Arnaud Delobelle <[EMAIL PROTECTED]> wrote: >... > decorated.sort() >... >>> def index(sequence): >>> return sorted(range(len(sequence)), key=sequence.__getitem__) >... >> But really these two versions of rank are slower than the original one >> (as s

Re: While we're talking about annoyances

2007-04-29 Thread Alex Martelli
Arnaud Delobelle <[EMAIL PROTECTED]> wrote: ... > > >> decorated.sort() ... > > def index(sequence): > > return sorted(range(len(sequence)), key=sequence.__getitem__) ... > But really these two versions of rank are slower than the original one > (as sorting a list is O(nlogn) wher

Re: While we're talking about annoyances

2007-04-29 Thread Raymond Hettinger
[Steven D'Aprano] > I recently needed to write a function to generate a rank table from a > list. That is, a list of ranks, where the rank of an item is the position > it would be in if the list were sorted: > > alist = list('defabc') > ranks = [3, 4, 5, 0, 1, 2] . . . > def rank(sequence): > t

Re: While we're talking about annoyances

2007-04-29 Thread Arnaud Delobelle
On Apr 29, 5:33 pm, Paul Rubin wrote: > Steven D'Aprano <[EMAIL PROTECTED]> writes: > > I recently needed to write a function to generate a rank table from a > > list. That is, a list of ranks, where the rank of an item is the position > > it would be in if the list were

Re: While we're talking about annoyances

2007-04-29 Thread Paul Rubin
Steven D'Aprano <[EMAIL PROTECTED]> writes: > I recently needed to write a function to generate a rank table from a > list. That is, a list of ranks, where the rank of an item is the position > it would be in if the list were sorted: > > alist = list('defabc') > ranks = [3, 4, 5, 0, 1, 2] fst = o

Re: While we're talking about annoyances

2007-04-29 Thread Arnaud Delobelle
On Apr 29, 11:46 am, Michael Hoffman <[EMAIL PROTECTED]> wrote: > GHUM wrote: > > Steven, > > >> def index(sequence): > >> decorated = zip(sequence, xrange(len(sequence))) > >> decorated.sort() > >> return [idx for (value, idx) in decorated] > > > would'nt that be equivalent code? > > >

Re: While we're talking about annoyances

2007-04-29 Thread Jarek Zgoda
Ben Finney napisał(a): >> On the other hand, there seem to be some progress that could be made >> to reduce the amount of work in writing documentation. >> Documentation in Esperanto instead of English maybe? > > Lojban http://www.lojban.org/> is both easier to learn world-wide > than Euro-biased

Re: While we're talking about annoyances

2007-04-29 Thread Ben Finney
"BJörn Lindqvist" <[EMAIL PROTECTED]> writes: > On the other hand, there seem to be some progress that could be made > to reduce the amount of work in writing documentation. > Documentation in Esperanto instead of English maybe? Lojban http://www.lojban.org/> is both easier to learn world-wide th

Re: While we're talking about annoyances

2007-04-29 Thread BJörn Lindqvist
On 4/29/07, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > To do that, I needed to generate an index table first. In the book > "Numerical Recipes in Pascal" by William Press et al there is a procedure > to generate an index table (46 lines of code) and one for a rank table > (five lines). 51 lines

Re: While we're talking about annoyances

2007-04-29 Thread Michael Hoffman
GHUM wrote: > Steven, > >> def index(sequence): >> decorated = zip(sequence, xrange(len(sequence))) >> decorated.sort() >> return [idx for (value, idx) in decorated] > > would'nt that be equivalent code? > > def index(sequence): > return [c for _,c in sorted((b,a) for a, b in >

Re: While we're talking about annoyances

2007-04-29 Thread GHUM
Steven, > def index(sequence): > decorated = zip(sequence, xrange(len(sequence))) > decorated.sort() > return [idx for (value, idx) in decorated] would'nt that be equivalent code? def index(sequence): return [c for _,c in sorted((b,a) for a, b in enumerate(sequence))] tested, g

While we're talking about annoyances

2007-04-29 Thread Steven D'Aprano
Am I the only one who finds that I'm writing more documentation than code? I recently needed to write a function to generate a rank table from a list. That is, a list of ranks, where the rank of an item is the position it would be in if the list were sorted: alist = list('defabc') ranks = [3, 4,