Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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='')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement