Re: Need a strange sort method...

2006-10-17 Thread Ron Adam
Ron Adam wrote: > Neil Cerutti wrote: >> On 2006-10-16, Tim Chase <[EMAIL PROTECTED]> wrote: >>> If you need it in a flat list, rather than as a list of >>> chunk_size lists (which are handy for iterating over in many >>> cases), there are ways of obtaining it, such as the hackish >>> >> sum([a

Re: Need a strange sort method...

2006-10-17 Thread Ron Adam
Neil Cerutti wrote: > On 2006-10-16, Tim Chase <[EMAIL PROTECTED]> wrote: >> If you need it in a flat list, rather than as a list of >> chunk_size lists (which are handy for iterating over in many >> cases), there are ways of obtaining it, such as the hackish >> > sum([a[i::chunk_size] for i in

Re: Need a strange sort method...

2006-10-16 Thread SpreadTooThin
Tim Chase wrote: > > for example: > > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > > > def cmp(i,j): #to be defined in this thread. > > Well, if you're willing to give up doing it in a cmp() method, > you can do it as such: > > >>> a.sort() > >>> chunk_size = 3 > >>> [a[i:

Re: Need a strange sort method...

2006-10-16 Thread [EMAIL PROTECTED]
SpreadTooThin wrote: > SpreadTooThin wrote: > > Simon Brunning wrote: > > > On 10/16/06, Simon Brunning <[EMAIL PROTECTED]> wrote: > > > > >>> a = [1,2,3,4,5,6,7,8,9,10] > > > > >>> a.sort(key=lambda item: (((item-1) %3), item)) > > > > >>> a > > > > [1, 4, 7, 10, 2, 5, 8, 3, 6, 9] > > > > > > Re-

Re: Need a strange sort method...

2006-10-16 Thread Gerard Flanagan
Gerard Flanagan wrote: > Gerard Flanagan wrote: > > SpreadTooThin wrote: > > > I have a list and I need to do a custom sort on it... > > > > > > for example: > > > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > > > > 1 4 7 10 > > > 2 5 8 > > > 3 6 9 > > > > > > > from math impor

Re: Need a strange sort method...

2006-10-16 Thread Paul Rubin
"SpreadTooThin" <[EMAIL PROTECTED]> writes: > > I have one extra 10 that I shouldn't... > > I think my loop termination is incorrect... It looks wrong to me; try your loop on range(20) and see what happens. > maybe I should just stop when my new series size is the same size as > the original? Y

Re: Need a strange sort method...

2006-10-16 Thread SpreadTooThin
SpreadTooThin wrote: > Simon Brunning wrote: > > On 10/16/06, Simon Brunning <[EMAIL PROTECTED]> wrote: > > > >>> a = [1,2,3,4,5,6,7,8,9,10] > > > >>> a.sort(key=lambda item: (((item-1) %3), item)) > > > >>> a > > > [1, 4, 7, 10, 2, 5, 8, 3, 6, 9] > > > > Re-reading the OP's post, perhaps sorting

Re: Need a strange sort method...

2006-10-16 Thread Gerard Flanagan
Gerard Flanagan wrote: > SpreadTooThin wrote: > > I have a list and I need to do a custom sort on it... > > > > for example: > > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > > 1 4 7 10 > > 2 5 8 > > 3 6 9 > > > > from math import sqrt > > for i in range(2,12): > seq = rang

Re: Need a strange sort method...

2006-10-16 Thread SpreadTooThin
Simon Brunning wrote: > On 10/16/06, Simon Brunning <[EMAIL PROTECTED]> wrote: > > >>> a = [1,2,3,4,5,6,7,8,9,10] > > >>> a.sort(key=lambda item: (((item-1) %3), item)) > > >>> a > > [1, 4, 7, 10, 2, 5, 8, 3, 6, 9] > > Re-reading the OP's post, perhaps sorting isn't what's required: > > >>> a[::3]

Re: Need a strange sort method...

2006-10-16 Thread Tim Chase
>>> that's trivial to do with slicing, of course. what makes you think you >>> need to do this by calling the "sort" method ? >>> >>> >> You are of course correct.. There might be a way to do this with >> slicing >> and i % 3 > > Slicing will work only with a sorted list. But modulus arithmeti

Re: Need a strange sort method...

2006-10-16 Thread Saizan
SpreadTooThin wrote: > > that's trivial to do with slicing, of course. what makes you think you > > need to do this by calling the "sort" method ? > > > > > > You are of course correct.. There might be a way to do this with > slicing > and i % 3 Slicing will work only with a sorted list. --

Re: Need a strange sort method...

2006-10-16 Thread Neil Cerutti
On 2006-10-16, Tim Chase <[EMAIL PROTECTED]> wrote: > If you need it in a flat list, rather than as a list of > chunk_size lists (which are handy for iterating over in many > cases), there are ways of obtaining it, such as the hackish > > >>> sum([a[i::chunk_size] for i in range(chunk_size)], []) >

Re: Need a strange sort method...

2006-10-16 Thread SpreadTooThin
Fredrik Lundh wrote: > SpreadTooThin wrote: > > > I have a list and I need to do a custom sort on it... > > > Its more like > > 1 4 7 10 > > 2 5 8 > > 3 6 9 > > that's trivial to do with slicing, of course. what makes you think you > need to do this by calling the "sort" method ? > > You are of

Re: Need a strange sort method...

2006-10-16 Thread Saizan
SpreadTooThin wrote: > I have a list and I need to do a custom sort on it... > > for example: > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > def cmp(i,j): #to be defined in this thread. > > a.sort(cmp) > > print a > [1,4,7,10, 2,5,8, 3,6,9] > > So withouth making this into a

Re: Need a strange sort method...

2006-10-16 Thread Tim Chase
> for example: > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > def cmp(i,j): #to be defined in this thread. Well, if you're willing to give up doing it in a cmp() method, you can do it as such: >>> a.sort() >>> chunk_size = 3 >>> [a[i::chunk_size] for i in range(chunk_si

Re: Need a strange sort method...

2006-10-16 Thread Gerard Flanagan
SpreadTooThin wrote: > I have a list and I need to do a custom sort on it... > > for example: > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > def cmp(i,j): #to be defined in this thread. > > a.sort(cmp) > > print a > [1,4,7,10, 2,5,8, 3,6,9] > > So withouth making this into a

Re: Need a strange sort method...

2006-10-16 Thread Simon Brunning
On 10/16/06, Simon Brunning <[EMAIL PROTECTED]> wrote: > >>> a = [1,2,3,4,5,6,7,8,9,10] > >>> a.sort(key=lambda item: (((item-1) %3), item)) > >>> a > [1, 4, 7, 10, 2, 5, 8, 3, 6, 9] Re-reading the OP's post, perhaps sorting isn't what's required: >>> a[::3] + a[1::3] + a[2::3] [1, 4, 7, 10, 2, 5

Re: Need a strange sort method...

2006-10-16 Thread Fredrik Lundh
SpreadTooThin wrote: > I have a list and I need to do a custom sort on it... > Its more like > 1 4 7 10 > 2 5 8 > 3 6 9 that's trivial to do with slicing, of course. what makes you think you need to do this by calling the "sort" method ? -- http://mail.python.org/mailman/listinfo/python-li

Re: Need a strange sort method...

2006-10-16 Thread Simon Brunning
On 16 Oct 2006 11:13:08 -0700, SpreadTooThin <[EMAIL PROTECTED]> wrote: > I have a list and I need to do a custom sort on it... > > for example: > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > def cmp(i,j): #to be defined in this thread. > > a.sort(cmp) > > print a > [1,4,7,10,

Re: Need a strange sort method...

2006-10-16 Thread Paul Rubin
"SpreadTooThin" <[EMAIL PROTECTED]> writes: > a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order > > def cmp(i,j): #to be defined in this thread. > > a.sort(cmp) > > print a > [1,4,7,10, 2,5,8, 3,6,9] def k(n): return (n-1) % 3, (n-1) // 3 a.sort(key=k) -- http://mail.python.org/m

Need a strange sort method...

2006-10-16 Thread SpreadTooThin
I have a list and I need to do a custom sort on it... for example: a = [1,2,3,4,5,6,7,8,9,10] #Although not necessarily in order def cmp(i,j): #to be defined in this thread. a.sort(cmp) print a [1,4,7,10, 2,5,8, 3,6,9] So withouth making this into an IQ test. Its more like 1 4 7 10 2 5 8 3 6