Need a strange sort method...

Simon Brunning simon at brunningonline.net
Mon Oct 16 20:36:30 CEST 2006


On 10/16/06, Simon Brunning <simon at brunningonline.net> 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, 8, 3, 6, 9]

-- 
Cheers,
Simon B
simon at brunningonline.net
http://www.brunningonline.net/simon/blog/



More information about the Python-list mailing list