Created
June 15, 2018 23:33
-
-
Save Fhernd/b9e80a8550aac2b7051e613facacdd9e to your computer and use it in GitHub Desktop.
Función generadora con datos extras. OrtizOL.
This file contains 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
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