Hola Carlos: Gracias por tu sugerencia. Como siempre hay mil formas de hacerse cosas. Saludos!
El 05/03/2012, a las 06:34, Carlos Zuniga <carlos....@gmail.com> escribió: > 2012/3/1 alito s <alit...@gmail.com>: >> Hola de nuevo: >> Ya tengo respuesta a mi pequeño dilema. >> Les pongo el código y espero que a alguien le sirva en un futuro. >> >> match1 = re.compile(r"^(>)(.+)(\n)(UGAGGUAGUAGGUUGUAU)(\w+)", re.MULTILINE) >> for match in match1.finditer(myfile): >> sequence = match.group() >> print sequence >> >> El detalle estaba en que cuando uno quiere buscar en diferentes líneas, >> tiene que utilizar MULTILINE, jeje... >> Si alguien tiene alguna sugerencia, es bienvenida. >> Saludos! > > Cuando necesito iterar sobre pares de algo utilizo está función: > > def iterpairs(iterable): > it = iter(iterable) > first = next(it) > for second in it: > yield first, second > first = second > > Que por ejemplo para 'ABCDE' devuelve AB, BC, CD y DE. > En caso del código en tu primer mensaje quedaría así: > > for line1, line2 in iterpairs(myfile): > match1 = re.search(r'(>)(.*)(\n)', line1) > match2 = re.search(r'(UGAGGUAGUAGGUUGUAU)(\w+)', line2) > if match2: > print match1.group() + "\n" > print match2.group() + "\n" > > > Saludos > > -- > Linux Registered User # 386081 > A menudo unas pocas horas de "Prueba y error" podrán ahorrarte minutos > de leer manuales. > _______________________________________________ > Python-es mailing list > Python-es@python.org > http://mail.python.org/mailman/listinfo/python-es > FAQ: http://python-es-faq.wikidot.com/ _______________________________________________ Python-es mailing list Python-es@python.org http://mail.python.org/mailman/listinfo/python-es FAQ: http://python-es-faq.wikidot.com/