Python Forum

Full Version: has anyone implemented a sort command in Python?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
(Dec-19-2018, 03:37 AM)ichabod801 Wrote: [ -> ]That's exactly what my code does (line 4): it converts the ip address to numeric, sorts based on that, and returns the strings.

that is the most sensible way to do that, given the ready availability of IP to int conversion tools. in C there were no tools like that and another way was also viable. what i wrote did numeric comparison by checking the length of the sequence of digits and comparing against a pre-loaded '0', the effect was like '127.000.000.001'. it was a bit slower than the conversion to an int, but it was part of a universal numeric comparison system, and assumed decimal even if there were leading zero digits. it compared octal correctly, anyway, if both keys were octal. it's the case of a mix of bases, or bases higher than 10, that could not handle. "0x12abff" looked like 3 numeric fields.

but i am now days doing enough networking in the cloud context that i need a sort command that do IP addresses. the way i would do it is add an "-a" option that works like "-n" does but does IP address conversion to int instead of a simple numeric one. if a flag is set the "-a" always sets then it searches for the key just the same way as in other cases, but once it has the key, it substitutes the digits to int conversion with address to int conversion and let the
Pages: 1 2