# Fazer diferentes combinações de palavras dentro de uma sentença
# https://pt.stackoverflow.com/q/197911/53463
import re
sujeito_re = re.compile(r"\b(gato|coelho)\b", re.IGNORECASE)
sentenca_re = re.compile(r"[^\n.]*?\b(subiu|caiu)\b[^\n.,]*?(\d+m\b)", re.IGNORECASE)
resultado = ()
texto = "O gato subiu no telhado de 10m, um homem jogou-lhe uma pedra e ele caiu de uma altura de 20m."
for sujeito in sujeito_re.finditer(texto):
pos = sujeito.end()
while True:
sentenca = sentenca_re.match(texto, pos)
if not sentenca:
break
resultado += (sujeito.group(1) + " " + sentenca.group(1) + " " + sentenca.group(2),)
pos = sentenca.end()
print (resultado)
IyBGYXplciBkaWZlcmVudGVzIGNvbWJpbmHDp8O1ZXMgZGUgcGFsYXZyYXMgZGVudHJvIGRlIHVtYSBzZW50ZW7Dp2EKIyBodHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvMTk3OTExLzUzNDYzCmltcG9ydCByZQoKc3VqZWl0b19yZSAgPSByZS5jb21waWxlKHIiXGIoZ2F0b3xjb2VsaG8pXGIiLCByZS5JR05PUkVDQVNFKQpzZW50ZW5jYV9yZSA9IHJlLmNvbXBpbGUociJbXlxuLl0qP1xiKHN1Yml1fGNhaXUpXGJbXlxuLixdKj8oXGQrbVxiKSIsIHJlLklHTk9SRUNBU0UpCnJlc3VsdGFkbyA9ICgpCgp0ZXh0byA9ICJPIGdhdG8gc3ViaXUgbm8gdGVsaGFkbyBkZSAxMG0sIHVtIGhvbWVtIGpvZ291LWxoZSB1bWEgcGVkcmEgZSBlbGUgY2FpdSBkZSB1bWEgYWx0dXJhIGRlIDIwbS4iCgoKZm9yIHN1amVpdG8gaW4gc3VqZWl0b19yZS5maW5kaXRlcih0ZXh0byk6CiAgICBwb3MgPSBzdWplaXRvLmVuZCgpCiAgICB3aGlsZSBUcnVlOgogICAgICAgIHNlbnRlbmNhID0gc2VudGVuY2FfcmUubWF0Y2godGV4dG8sIHBvcykKICAgICAgICBpZiBub3Qgc2VudGVuY2E6CiAgICAgICAgICAgIGJyZWFrCiAgICAgICAgcmVzdWx0YWRvICs9IChzdWplaXRvLmdyb3VwKDEpICsgIiAiICsgc2VudGVuY2EuZ3JvdXAoMSkgKyAiICIgKyBzZW50ZW5jYS5ncm91cCgyKSwpCiAgICAgICAgcG9zID0gc2VudGVuY2EuZW5kKCkKICAgICAgICAKcHJpbnQgKHJlc3VsdGFkbyk=