Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created June 15, 2018 23:33
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 Fhernd/b9e80a8550aac2b7051e613facacdd9e to your computer and use it in GitHub Desktop.
Save Fhernd/b9e80a8550aac2b7051e613facacdd9e to your computer and use it in GitHub Desktop.
Función generadora con datos extras. OrtizOL.
from collections import deque
class HistorialLineas:
def __init__(self, lineas, longitud = 5):
self.lineas = lineas
self.historial = deque(maxlen=longitud)
def __iter__(self):
for numero_linea, linea in enumerate(self.lineas, 1):
self.historial.append((numero_linea, linea))
yield linea
def remover(self):
self.historial.clear()
if __name__ == '__main__':
with open('python.txt', 'r') as f:
lineas = HistorialLineas(f)
for linea in lineas:
if 'Software' in linea:
for numero_linea, historial_linea in lineas.historial:
print('{}:{}'.format(numero_linea, historial_linea), end='')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment