[Tutor] IP sorting
Wed, 26 Dec 2001 23:23:58 -0500
> All is good, it works well, however it only sorts to the second place of
> the last octet. For example...
> 192.168.100.118 --- 5 hits
> 192.168.100.119 --- 10 hits
> 192.168.100.12 --- 3 hits
> 192.168.100.120 --- 22 hits
> How do I get the 192.168.100.12 to go where it supposed to (at
> the beginning)?
Actually, it *is* sorting to the fourth octet. Look at what you have:
If you asked Python to compare '12' and '120' it would tell you that the
former is 'less' than the latter. In order to get a true numerical sort,
you need to convert the octets (all of them, not just the fourth) to actual
numbers when sorting. Or, more kludgey, convert two-digit octets to three
with a leading zero.
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com