Need a strange sort method...

Tim Chase python.list at tim.thechases.com
Mon Oct 16 16:00:33 EDT 2006


>>> that's trivial to do with slicing, of course.  what makes you think you
>>> need to do this by calling the "sort" method ?
>>>
>>> </F>
>> 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 arithmetic will only work with contiguous, 
non-repeating numeric sequences...Funky things happen with 
sequences like

[1,2,3,4,4,5,6,7,8,9,10] # "4" appears twice

or

[1,3,5,7,11,13,17,19,23,29]

where the position and the numeric value no longer correlate via 
a simple modulus.

-tkc






More information about the Python-list mailing list