def _find(self, texto, patron): """Returns the index of the firste element of pattern 'patron' in the list 'texto'. I.e., if texto=[1,2,3,4,5,6] and patron=[2,3] then _find should return 1.""" base = 0 indice = 0 try: while texto != []: indice = texto.index(patron[0]) if indice != -1: for i in range(len(patron)): if not texto[indice + i] == patron[i]: base += indice indice = -1 break break else: texto = texto[base:] except ValueError, IndexError: indice = -1 base = 0 return indice + base