sorting many arrays from one...

Alex Martelli aleax at aleax.it
Tue Jul 9 08:48:19 EDT 2002


Shagshag13 wrote:

> hello,
> 
> i'm looking for an "efficient" way of sorting many arrays driven by one,
> for example
> 
> drive = [1, 4, 2, 3]
> other1 = [a, b, c, d]
> other2 = [ k, j, h, l ]
> other3 = [14, 18, 19, 11]
> 
> and i get :
> 
> drive = [1, 2, 3, 4]
> other1 = [a, c, d, b]
> other2 = [ k, h, l, j]
> other3 = [14, 19, 11, 18]

aux_list = zip(drive, other1, other2, other3)
aux_list.sort()

for i in range(len(drive)):
    drive[i], other1[i], other2[i], other3[i] = aux_list[i]


Alex




More information about the Python-list mailing list