[Tutor] IP sorting
Karthik Gurumurthy
karthikg@aztec.soft.net
Thu, 27 Dec 2001 12:17:34 +0530
this one is cool and so was danny's.
i have a question here though.
why do we need to convert to a tuple?
lot = [tuple(map(int, ip.split("."))) for ip in iplist]
is there any specific reason. Python does not know to sort a list of lists?
karthik.
-----Original Message-----
From: tutor-admin@python.org [mailto:tutor-admin@python.org]On Behalf Of
Roman Suzi
Sent: Thursday, December 27, 2001 11:46 AM
To: tutor@python.org
Subject: RE: [Tutor] IP sorting
Nice problem! Here is my solution (for Python 2.x)
iplist = [
"195.168.1.123",
"192.168.1.123",
"192.168.1.111",
"192.168.1.11",
]
lot = [tuple(map(int, ip.split("."))) for ip in iplist]
lot.sort()
iplist1 = [".".join(map(str, addr)) for addr in lot]
print iplist1
Sincerely yours, Roman A.Suzi
--
- Petrozavodsk - Karelia - Russia - mailto:rnd@onego.ru -
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor