[Tutor] Sorting more than one list
Brian van den Broek
bvande at po-box.mcgill.ca
Thu Mar 31 01:28:51 CEST 2005
Diego Galho Prestes said unto the world upon 2005-03-30 21:19:
> Hi!
>
> I need to sort 4 lists but I need that they make the "sort together".
> I'll sort just one but when I change the position of the items of the
> 1st list I have to change the positions of the other 3 lists. Can I do
> this just using the sort() method of the list object?
> If I can't, someone know a site that have one sort method in python that
> its easily to implement and fast?
>
> Tks,
> Diego
>
Hi Diego,
I'm not quite following your question. Why can't you just sort each
list one at a time? Is it that you want a quick way to do that all at
once, rather than writing 4 separate sort statements?
If that is what you need, perhaps this helps?:
>>> def bulk_sort(*lists):
for a_list in lists:
a_list.sort()
>>> list_1 = [3, 2, 5, 7, 1]
>>> list_2 = [4, 3, 7, 2]
>>> list_3 = [3, 2, 1]
>>> bulk_sort(list_1, list_2, list_3)
>>> list_1
[1, 2, 3, 5, 7]
>>> list_2
[2, 3, 4, 7]
>>> list_3
[1, 2, 3]
>>>
If that's not what you meant, perhaps you can clarify your desire?
HTH,
Brian vdB
More information about the Tutor
mailing list