Created
January 16, 2026 17:23
-
-
Save angelbladex/89208079ac2888ff5d38d310eab74b0f to your computer and use it in GitHub Desktop.
Ordenar lista de dominios junto a sus subbominios de forma anidada
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Lee el archivo | |
| with open('dominios.txt', 'r') as f: | |
| lineas = [linea.strip() for linea in f if linea.strip()] | |
| # Función personalizada para ordenar | |
| def dominio_sort_key(dominio): | |
| partes = dominio.split('.') | |
| # Invertir para ordenar por dominio principal primero | |
| return tuple(reversed(partes)) | |
| # Ordena | |
| lineas_ordenadas = sorted(lineas, key=dominio_sort_key) | |
| # Guarda el resultado | |
| with open('dominios_ordenados.txt', 'w') as f: | |
| for dominio in lineas_ordenadas: | |
| f.write(dominio + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment