[Tutor] sorting data from multiple arrays

Jeff Peery jeffpeery at yahoo.com
Thu Mar 22 18:59:08 CET 2007


hello, I typically run into this problem and I'm not always sure of the most efficient way to handle it. I often work with multiple arrays of data, say arrays a, b, and c, and I want to sort the elements of b and c based on a. for example:

a = [3,2,1,4]
b = ['hi', 'my','name', 'is']
c = [5,2,4,2]

I order 'a' from small to large and do the same rearrangement to 'b' and 'c':
a = [1,2,3,4]
 b = ['name', 'my','hi', 'is']
 c = [4,2,5,2]

usually I do some terrible looking for loops and iterate over the whole mess.... is there a clean, efficient way to do this, or is there a nice function that would reorder the elements of b and c based on the soring of a?

thanks

 
---------------------------------
Don't be flakey. Get Yahoo! Mail for Mobile and 
always stay connected to friends.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070322/ddc81056/attachment-0001.html 


More information about the Tutor mailing list