Sorting a list depending of the indexes of another sorted list

J. Peng jpeng at block.duxieweb.com
Mon Jan 21 03:03:37 EST 2008


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:
[('10', 'mx1.domain.com'), ('20', 'mx2.domain.com'), ('30', 
'anotherhost.domain.com')]



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.domain.com"]
> 



More information about the Python-list mailing list