[BangPypers] How to sort the IP(s)

Prashanth Ellina prashanthellina at gmail.com
Thu May 8 11:07:43 CEST 2008


This is one way.

make_num = lambda ip: [int(p) for p in ip.split('.')]
ips = ['192.168.1.1','172.18.13.2', '192.168.20.1']
ips = [(make_num(ip), ip) for ip in ips]
ips.sort()
ips.reverse()
ips = [ip[1] for ip in ips]

On Thu, May 8, 2008 at 11:53 PM, Kushal Das <kushaldas at gmail.com> wrote:

> Hi,
> What is the best way to sort IP numbers
> numbers like
> 192.168.20.1
> 192.168.1.1
> 172.18.13.2
>
>
> Kushal
> --
> Fedora Ambassador, India
> http://kushaldas.in
> http://dgplug.org (Linux User Group of Durgapur)
>
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> http://mail.python.org/mailman/listinfo/bangpypers
>



-- 
http://blog.prashanthellina.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/bangpypers/attachments/20080508/a65963ca/attachment.htm>


More information about the BangPypers mailing list