<jupyter_start><jupyter_text>Python | Programación funcional Ejercicio 11. Utiliza `reduce` para concatenar estas palabras en una frase```Pythonejer_1 = ("to", "be", "or", "not", "to", "be", "that", "is", "the", "question")```<jupyter_code>from functools import reduce
ejer_1 = ("to", "be", "or", "not", "to", "be", "that", "is", "the", "question")

reduce(lambda x,y: x + " " + y, ejer_1)
# con join
" ".join(ejer_1)<jupyter_output><empty_output><jupyter_text>2. Obtén una nueva tupla con el cuadrado de cada elemento de la siguiente tupla```Pythonejer_2 = (1,2,3,4,5)```<jupyter_code>ejer_2 = (1,2,3,4,5)

tuple(map(lambda x: x**2, ejer_2))<jupyter_output><empty_output><jupyter_text>3. Filtra aquellos elementos que sean multiplos de 3 o de 5```Pythonejer_3 = (1,2,3,4,5,15,21,22,33,34,35)```<jupyter_code>ejer_3 = (1,2,3,4,5,15,21,22,33,34,35)

def mult_3_5(x):
    if x % 3 == 0 or x % 5 == 0:
        return True
    return False

tuple(filter(mult_3_5, ejer_3))
tuple(filter(lambda x: True if x%3 == 0 or x%5 == 0 else False, ejer_3))
tuple(filter(lambda x: x%3 == 0 or x%5 == 0, ejer_3))<jupyter_output><empty_output><jupyter_text>4. Convierte la siguiente tupla de pesetas a euros```Pythonejer_4 = (1000, 8000, 20000000, 40000000)```<jupyter_code>ejer_4 = (1000, 8000, 20000000, 40000000)

tuple(map(lambda x: round(x/166.38,2), ejer_4))<jupyter_output><empty_output><jupyter_text>5. Convierte la siguiente lista de desconocidos a mayusculas```Pythonejer_5 = ("Arya", "John", "Robb", "Bran", "Sansa", "Rickon")```<jupyter_code>ejer_5 = ("Arya", "John", "Robb", "Bran", "Sansa", "Rickon")

tuple(map(lambda x: x.upper(), ejer_5))<jupyter_output><empty_output><jupyter_text>6. Realiza un conversor de dias de la semana en texto a numerico (1-7), usando `map`.```Pythonejer_6 = ("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo")```<jupyter_code>ejer_6 = ("Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo")

finde = ("Viernes", "Sábado", "Domingo")
#way 1
def conversor_dias_semana(x):
    if x == "Lunes":
        return 1
    elif x == "Martes":
        return 2
    elif x == "Miércoles":
        return 3
    elif x == "Jueves":
        return 4
    elif x == "Viernes":
        return 5
    elif x == "Sábado":
        return 6
    elif x == "Domingo":
        return 7
    else:
        return 9999
    
tuple(map(conversor_dias_semana, finde))
#way 2
dictionari = {"Lunes": 1,
             "Martes": 2,
             "Miércoles": 3,
             "Jueves": 4,
             "Viernes": 5,
             "Sábado": 6,
             "Domingo": 7}

#puedes crear tu diccionario de la manera que prefieras, manualmente es una de las opciones pero también puedes:
dictionari2 = {k:v for k,v in zip(ejer_6,range(1,8))}

tuple(map(lambda x: dictionari2[x], finde))
#way 3
def diasemana_a_numero(dia_semana):
    dias_semana = ["Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"]
    
    if dia_semana in dias_semana:
        return dias_semana.index(dia_semana) + 1
    else:
        print(f"{dia_semana} no es un día de la semana, try again!")
        return -1

tuple(map(diasemana_a_numero, ['Martes', 'Algo']))
tuple(map(diasemana_a_numero, finde))
#way 4
#necesita de la lista con los días de la semana ejer_6

tuple(list(map(lambda x: range(1,8)[ejer_6.index(x)], finde)))
#way 5
#necesita de la lista con los días de la semana ejer_6

tuple(list(map(lambda x: ejer_6.index(x) + 1, finde)))<jupyter_output><empty_output><jupyter_text>7. Utiliza `map` para multiplicar elemento a elemento estas dos tuplas```Pythonejer_7_1 = (2, 5, 8)ejer_7_2 = (6, 3, 2)```<jupyter_code>ejer_7_1 = (2, 5, 8)
ejer_7_2 = (6, 3, 2)

def multiplica(x, y):
    return x * y

tuple(map(multiplica, ejer_7_1, ejer_7_2))
tuple(map(lambda x,y: x*y, ejer_7_1, ejer_7_2))<jupyter_output><empty_output><jupyter_text>8. Crea una tupla nueva con todos los coches que no sean VW :)```Pythonejer_8 = ("VW", "Audi", "Renault", "VW", "BMW")```<jupyter_code>ejer_8 = ("VW", "Audi", "Renault", "VW", "BMW")

tuple(filter(lambda x: x != "VW",ejer_8))<jupyter_output><empty_output><jupyter_text>9. Dadas las siguientes fechas en formato string, quedate con aquellas del año 2020```Pythonejer_9 = ("2019-04-08", "2020-10-10", "2020-01-22", "2019-07-13", "2019-02-01"]```<jupyter_code>ejer_9 = ["2019-04-08", "2020-10-10", "2020-01-22", "2019-07-13", "2019-02-01"]

def este_anio(x):
    if "2020" in x:
        return True
    return False

tuple(filter(este_anio, ejer_9))
tuple(filter(lambda x: True if "2020" in x else False, ejer_9))
ejer_9 = ["2019-04-08", "2020-10-10", "2020-01-22", "2019-07-13", "2019-02-01"]
tuple(filter(lambda x: x if "2020" in x, ejer_9))<jupyter_output><empty_output><jupyter_text>10. Filtra aquellos strings que sean [palíndromos](https://es.wikipedia.org/wiki/Pal%C3%ADndromo)```Pythonejer_10 = ("php", "w3r", "Python", "abcd", "Java", "aaa")```<jupyter_code>ejer_10 = ("php", "w3r", "Python", "abcd", "Java", "aaa")

tuple(filter(lambda x: (x == "".join(reversed(x))), ejer_10))<jupyter_output><empty_output><jupyter_text>Bonus Track.- Resuelve esta kata usando `map`https://www.codewars.com/kata/554b4ac871d6813a03000035Nota: si es demasiado difícil intenta resolverla sin usar `map` y si lo consigues, vuelve a resolverla usando `map`.<jupyter_code>def high_and_low(numbers):
    n = list(map(int, numbers.split(' ')))
    return "{} {}".format(max(n), min(n))

high_and_low("1 2 3 4 5")
from functools import reduce
ejer_10 = ("php", "w3r", "Python", "abcd", "Java", "aaa")
reduce(lambda x, y: x + " - " + y, ejer_10)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17820900836745593, 'fraction_numerical': 0.07103435997863629, 'mean_word_length': 4.809720785935884, 'pattern_counts': {'":': 14, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '97593', 'license': 'MIT', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2408, 'n_words': 552, 'path': 'week3_course_python_III/day3_python_IX/exercises_programacion_funcional_RES.ipynb', 'repo_name': 'paleomau/MGOL_BOOTCAMP', 'size': '5617'}