Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 10, 2022 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/64c9c864536b4fee0735ab1b86ec5cb5 to your computer and use it in GitHub Desktop.
Save parzibyte/64c9c864536b4fee0735ab1b86ec5cb5 to your computer and use it in GitHub Desktop.
def burbuja(arreglo):
longitud = len(arreglo)
for i in range(longitud):
for indice_actual in range(longitud - 1):
indice_siguiente_elemento = indice_actual + 1
if arreglo[indice_actual]["año"] < arreglo[indice_siguiente_elemento]["año"]:
arreglo[indice_siguiente_elemento], arreglo[indice_actual] = arreglo[indice_actual], arreglo[indice_siguiente_elemento]
def guardar_años_cronologicamente():
lista = obtener_lista_facturacion()
burbuja(lista)
with open(NOMBRE_ARCHIVO_ESCRITURA, "w", encoding="utf-8") as archivo:
for elemento in lista:
año = elemento["año"]
total = (elemento["trimestre1"] + elemento["trimestre2"] +
elemento["trimestre3"] + elemento["trimestre4"])
archivo.write(f"Año {año} facturación anual de: {total} euros.\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment