Python Forum
program/scrpt wanted (in python, of course)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
program/scrpt wanted (in python, of course)
#2
A list to test would make it easier.
Here something I threw together. Might get you started.
ip_address = [
    '192.168.0.1',
    '192.168.0.5',
    '20.101.24.5',
    '101.17.31.8',
    '41.37.101.40',
    '41.37.101.4'
    ]
    
def sort_ip(key):
    if key.count('.') == 3:
        return 4, [k.rjust(3) for k in key.split('.')]
    else:
        # need more data for dealing with ipv6 address
        return 6, [k.rjust(4) for k in key.split(':')]
    
def main():    
    ip_address.sort(key=sort_ip)
    for ip in ip_address:
        print(ip)
    
main()
99 percent of computer problems exists between chair and keyboard.
Reply


Messages In This Thread
RE: program/scrpt wanted (in python, of course) - by Windspar - Oct-21-2017, 04:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Python Developer Wanted] ‘Women in Tech’ Worldwide Training Initiative from Oxford vanicci 2 2,866 Jun-27-2018, 04:25 PM
Last Post: vanicci
  Command wanted in Python: mgrep Skaperen 1 2,854 Mar-13-2018, 07:38 AM
Last Post: Gribouillis
  Can a python program execute an action on another software program? lex 4 3,999 Jan-26-2018, 03:10 PM
Last Post: buran
  wanted: python code: sleep to a time period Skaperen 2 6,608 Nov-06-2017, 03:00 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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