From 7f6426e0eec6cf6e89356027b55d0f4628f26f39 Mon Sep 17 00:00:00 2001 From: Manuel Vergara Date: Sat, 30 Sep 2023 22:26:15 +0200 Subject: [PATCH] Update exercises 18 Signed-off-by: Manuel Vergara --- .../18_Expresiones_regulares/01_regex.py | 14 ++++++++++++++ .../18_Expresiones_regulares/README.md | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/30-days-of-python/18_Expresiones_regulares/01_regex.py b/30-days-of-python/18_Expresiones_regulares/01_regex.py index 73b827f..1e2ab54 100644 --- a/30-days-of-python/18_Expresiones_regulares/01_regex.py +++ b/30-days-of-python/18_Expresiones_regulares/01_regex.py @@ -108,3 +108,17 @@ for word in words: most_freq_words = sorted(word_freq, key=word_freq.get, reverse=True)[:3] print("Las tres palabras más frecuentes son:", most_freq_words) + +# Ejercicios: Nivel 4 + +# 1. Extrae el DNI de la siguiente cadena. + +dni = """Asunto: Datos para la nómina. +Respondiendo a su mail, le paso el dato personal que le faltaba. Mi DNI es 12345678A. +Saludos. +""" + +# Extraemos el DNI +dni = re.search(r'\d{8}[A-Z]', dni).group() + +print("DNI:", dni) diff --git a/30-days-of-python/18_Expresiones_regulares/README.md b/30-days-of-python/18_Expresiones_regulares/README.md index 99ade05..f32de83 100644 --- a/30-days-of-python/18_Expresiones_regulares/README.md +++ b/30-days-of-python/18_Expresiones_regulares/README.md @@ -69,6 +69,18 @@ print(clean_text(sentence)); I am a teacher and I love teaching There is nothing as more rewarding as educating and empowering people I found teaching more interesting than any other jobs Does this motivate you to be a teacher print(most_frequent_words(cleaned_text)) # [(3, 'I'), (2, 'teaching'), (2, 'teacher')] ``` + +### Ejercicios: Nivel 4 + +1. Extrae el DNI de la siguiente cadena. + +``` +dni = """Asunto: Datos para la nómina. +Respondiendo a su mail, le paso el dato personal que le faltaba. Mi DNI es 12345678A. +Saludos. +""" +``` + [Solución](01_regex.py) [<< Day 17](../17_Manejo_de_excepciones/README.md) | [Day 19 >>](../19_Manipulación_de_archivos/README.md)