From 91131a7e79484d004b3a04ad086971a030460bae Mon Sep 17 00:00:00 2001 From: Ulzahk Date: Wed, 2 Sep 2020 09:27:05 -0500 Subject: [PATCH] Challenge's answer using open().readlines(), re.compile() and re.findall() --- src/main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main.py b/src/main.py index 3f1ef43..eb56005 100644 --- a/src/main.py +++ b/src/main.py @@ -1,8 +1,24 @@ -# Resolve the problem!! - +import re def run(): - # Start coding here + file_path = 'src/encoded.txt' + regex = '[a-z]+' + pattern = re.compile(regex) + secret_message = '' + + with open(file_path, 'r', encoding='utf-8') as f: + + for line in f.readlines(): + secret_message += ''.join(re.findall(pattern, line)) + + # Other way to get the secret message, remember to comment the other loop to make this one work + """ for i, line in enumerate(f): + for match in re.finditer(pattern, line): + secret_message += match.group() """ + + f.close() + + print(secret_message) if __name__ == '__main__':