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"] > -- http://mail.python.org/mailman/listinfo/python-list