Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- En este código de Python organizaremos grupos de paquetes organizados de líneas de acuerdo a su cantidad de caracteres.
- #!/usr/bin/python3
- texto = """0123456789
- 1234567890
- 2345678901
- 3456789012
- 4567890123xxxxxxx
- 5678901234
- 6789012345x
- 7890123456
- 8901234567890123456789012345678901234567890123456789
- 9012345678
- 8765432109
- 7654321098x
- 6543210987
- 5432109876"""
- paquete = []
- maxlenght = 44
- contenido = ""
- conteo = 0
- line = texto.split("\n")
- i = -1
- while i < len(line)-1:
- i+=1
- conteo += len(line[i]) +1
- if len(line[i]) +1 > maxlenght:
- i += 1
- if conteo <= maxlenght:
- contenido += line[i] + "\n"
- if i == len(line)-1:
- paquete += [contenido]
- elif conteo >= maxlenght:
- conteo = 0
- paquete += [contenido]
- contenido = ""
- i -=1
- for i in paquete:
- print(i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement