Python Forum
has anyone implemented a sort command in Python?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
has anyone implemented a sort command in Python?
#11
(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
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how operators are implemented as function calls Skaperen 5 3,438 Dec-15-2018, 03:14 AM
Last Post: ichabod801
  Ugh, Someone Went and Implemented Case ichabod801 2 2,705 Sep-15-2017, 09:46 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020