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/