All pastes #469106 Raw Edit

Unnamed

public python v1 · immutable
·published 2007-05-03 15:31 UTC
rendered paste body
    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 and texto[indice:indice+len(patron)] != patron:                    #print "O patron", patron, "non esta na posicion", indice, "ca base", base, "do texto", texto                                                                    base  += indice + 1                    texto  = texto[indice + 1:]                else:                    break        except ValueError, IndexError:            indice = -1            base   = 0        return indice + base