On Thu, May 8, 2008 at 2:47 PM, Anand Balachandran Pillai <[EMAIL PROTECTED]> wrote: > Do you really need any kind of additional processing ? > > The basic sort algorithm is smart enough to do this by itself, > >>> l=['192.168.1.1','172.18.13.2','192.168.3.2','172.19.2.1'] > >>>l.sort() > >>>l > ['172.18.13.2', '172.19.2.1', '192.168.1.1', '192.168.3.2'] > > or use sorted(...) if you don't want to modify in place... > > Here is an even closer example to demo this... > >>> > l=['192.168.12.21','192.168.12.15','192.168.11.10','192.168.10.5','192.168.15.1','192.167.10.1'] > >>> sorted(l) > ['192.167.10.1', '192.168.10.5', '192.168.11.10', '192.168.12.15', > '192.168.12.21', '192.168.15.1']
What about this? >>> ips = ['192.168.20.1', '192.168.1.1', '172.18.13.2', '27.118.13.2'] >>> sorted(ips) ['172.18.13.2', '192.168.1.1', '192.168.20.1', '27.118.13.2'] You need to sort them as tuples of 4 numbers not as strings. _______________________________________________ BangPypers mailing list [email protected] http://mail.python.org/mailman/listinfo/bangpypers
