[BangPypers] How to sort the IP(s)

Anand Chitipothu anandology at gmail.com
Thu May 8 11:11:04 CEST 2008


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

ips = ['192.168.20.1', '192.168.1.1', '172.18.13.2']
sorted(ips, key=lambda ip: [int(x) for x in ip.split('.')])

# ips.sort(key=lambda ip: [int(x) for x in ip.split('.')]) if you want
to sort in-place.


More information about the BangPypers mailing list