Wednesday, March 4, 2020

Python - Sorting interface names

This is actually harder than I thought. I was wondering if someone here already did it:

How do you sort interfaces correctly, given the following example:

te1/0/1

te1/0/10

te1/0/11

te1/0/12

te1/0/2

te1/0/3

te1/0/4

te1/0/5

te1/0/6

te1/0/7

te1/0/8

te1/0/9

te2/0/1

te2/0/2

te2/0/3

te2/0/4

te3/0/1

I was thinking of sorting by regex(The digits after the last /slash/) but that won't work because it will sort te2/0/1 before te1/0/2.

I fell like I'll have to write some convoluted function just to get this right.



No comments:

Post a Comment