Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread Peter Otten
Steven D'Aprano wrote: >> The following relies on undocumented (I hope) behaviour: > preferences = [10, 30, 20] > hosts = [ "mx1.domain.com", "anotherhost.domain.com", >>... "mx2.domain.com"] > hosts.sort(key=lambda x, p=iter(preferences).next: p()) > preferences.sort() > ho

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread Steven D'Aprano
On Mon, 21 Jan 2008 09:53:10 +0100, Peter Otten wrote: > Santiago Romero wrote: > >> I'm trying to sort both lists so that they end like this: >> >> preferences = [10, 20, 30] >> hosts = [ "mx1.domain.com", "mx2.domain.com", "anotherhost.domain.com" >> ] >> >> I want to sort hosts list depen

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread Steven D'Aprano
On Mon, 21 Jan 2008 17:32:42 +0800, J. Peng wrote: > Steven D'Aprano 写道: >> On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote: >> >>> J. Peng 写道: >>> k = (i.split())[3] y = (i.split())[1] >>> btw, why can't I write the above two into one statement? >>> >>> (k,y) = (i.split())[3,1]

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread Santiago Romero
Thanks all for the answers ... I'll use a tuple as you said :) Anyway, is interesting to know how to sort 2 lists when you dont want to use tuples, so thanks also to Peter :) > Then one have to split the list twice.Given the list is large,it's maybe > not good for performance.Is it a more effe

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread J. Peng
Steven D'Aprano 写道: > On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote: > >> J. Peng 写道: >> >>>k = (i.split())[3] >>>y = (i.split())[1] >> btw, why can't I write the above two into one statement? >> >> (k,y) = (i.split())[3,1] > > I don't know. What's "i"? > > I'm guessing "i" is a stri

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread Steven D'Aprano
On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote: > J. Peng 写道: > >>k = (i.split())[3] >>y = (i.split())[1] > > btw, why can't I write the above two into one statement? > > (k,y) = (i.split())[3,1] I don't know. What's "i"? I'm guessing "i" is a string (and what a horrible choice of

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread Peter Otten
Santiago Romero wrote: > I'm trying to sort both lists so that they end like this: > > preferences = [10, 20, 30] > hosts = [ "mx1.domain.com", "mx2.domain.com", > "anotherhost.domain.com" ] > > I want to sort hosts list depending on the numeric order of > "preferences". The following relies

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread J. Peng
J. Peng 写道: >k = (i.split())[3] >y = (i.split())[1] btw, why can't I write the above two into one statement? (k,y) = (i.split())[3,1] -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a list depending of the indexes of another sorted list

2008-01-21 Thread J. Peng
I tried to write it below,it can work,:) v= """preference 10 host mx1.domain.com preference 30 host anotherhost.domain.com preference 20 host mx2.domain.com""" x=v.split("\n") li =[] for i in x: k = (i.split())[3] y = (i.split())[1] li.append((y,k)) li.sort() print li the output is:

Re: Sorting a list depending of the indexes of another sorted list

2008-01-20 Thread babui
On 21 ene, 08:41, Santiago Romero <[EMAIL PROTECTED]> wrote: > Hi ... > > I have the following DNS MX records info: > > domain.com > preference 10 host mx1.domain.com > preference 30 host anotherhost.domain.com > preference 20 host mx2.domain.com > And finally ... do you think there is a bette

Sorting a list depending of the indexes of another sorted list

2008-01-20 Thread Santiago Romero
Hi ... I have the following DNS MX records info: domain.com preference 10 host mx1.domain.com preference 30 host anotherhost.domain.com preference 20 host mx2.domain.com I'm storing this info in 2 lists: preferences = [10, 30, 20] hosts = [ "mx1.domain.com", "anotherhost.domain.com", "mx2.d