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
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
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:
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-
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
"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
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
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
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]
>>> 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
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.
--
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)], [])
>
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
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
> 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
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
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
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
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,
"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
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
21 matches
Mail list logo