Month: September 2023

Network Interface Name Sorting in Python

Evergreen problem in sorting strings: How do you implement human-expected ordering when the strings have varying-length numbers in them? Prime example in the networking world is network interface naming in various devices. Example: >>> interfaces = [“1/1/1”, “1/1/2”, “1/1/10”, “1/1/11”, “1/1/10.32”, “1/1/10.311”, “1/1/10.312”, “eth-1/1/1.1”, “eth-1/1/1.2”, “eth-1/1/1.10”]>>> print(“\n”.join(sorted(interfaces)))1/1/11/1/101/1/10.3111/1/10.3121/1/10.321/1/111/1/2eth-1/1/1.1eth-1/1/1.10eth-1/1/1.2>>> That’s not ideal as the default string sorting […]