Sorting a list depending of the indexes of another sorted list
Santiago Romero
sromero at gmail.com
Mon Jan 21 02:41:13 EST 2008
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"]
(I was about to use a dict of preferences : domain, but it's
possible to find 2 mx records with the same preference, so keys
wouldnt be unique).
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".
And finally ... do you think there is a better python structure to
store this data and sort it in a more easy way?
Thanks.
More information about the Python-list
mailing list