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, 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 9
>>> 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] -- Cheers, Simon B [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list