Skip to content

Commit 73131ed

Browse files
authored
Merge pull request mouredev#3295 from yenneralayon142/main
#15 , #16 , #17 y #18 PYTHON
2 parents 0524fef + d8d3b0e commit 73131ed

File tree

4 files changed

+156
-0
lines changed

4 files changed

+156
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import asyncio
2+
import datetime
3+
import time
4+
5+
"""
6+
Asincronismo
7+
"""
8+
9+
async def task(name:str, duration:int):
10+
print(
11+
f"Tarea: {name}. Duración: {duration}s. Inicio: {datetime.datetime.now()}")
12+
await asyncio.sleep(duration)
13+
print(
14+
f"Tarea: {name}. Fin: {datetime.datetime.now()}"
15+
)
16+
17+
asyncio.run(task("1",2))
18+
19+
"""
20+
Extra
21+
"""
22+
23+
async def async_task():
24+
await asyncio.gather(task("A",3), task("B",2), task("C",1))
25+
await task("D",1)
26+
27+
asyncio.run(async_task())
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import re
2+
3+
"""
4+
Expresiones Regulares
5+
"""
6+
def find_numbers(text:str) -> list:
7+
return re.findall(r"\d+",text)
8+
9+
print(find_numbers("Este es el ejercicio 16 publicado 15/04/2024."))
10+
11+
12+
13+
"""
14+
Extra
15+
"""
16+
17+
def validate_email(email:str) -> bool:
18+
return bool(re.match(r"^[\w.+-]+@[\w]+\.[a-zA-Z]+$",email))
19+
print(validate_email("[email protected]"))
20+
21+
def validate_phone(phone:str) -> bool:
22+
return bool(re.match(r"^\+?[\d\s]{3,}$",phone))
23+
print(validate_phone("+57 311 200 66 77"))
24+
25+
def validate_url(url: str) -> bool:
26+
return bool(re.match(r"^http[s]?://(www.)?[\w]+\.[a-zA-Z]{2,}$", url))
27+
print(validate_url("http://www.moure.dev"))
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"""
2+
Iteraciones
3+
"""
4+
5+
# FOR
6+
7+
for i in range(1,11):
8+
print(i)
9+
10+
#WHILE
11+
12+
i = 1
13+
while i <= 10:
14+
print(i)
15+
i += 1
16+
17+
# RECURSIVIDAD
18+
def count_ten(i = 1):
19+
if i <= 10:
20+
print(i)
21+
count_ten(i + 1)
22+
count_ten()
23+
24+
25+
"""
26+
Ejercicio
27+
"""
28+
29+
for i in [1,2,3,4,5,6,7,8,9,10]:
30+
print(i)
31+
32+
for i in {1,2,3,4,5,6,7,8,9}:
33+
print(i)
34+
35+
for i in {1:"a",2:"b",3:"c",4:"d",5:"e",6:"f",7:"h",8:"i"}:
36+
print(i)
37+
38+
print(*[i for i in range(1,20)], sep='\n')
39+
40+
for i in "Ubosque":
41+
print(i)
42+
43+
for i in reversed([1,2,3,4]):
44+
print(i)
45+
46+
for i in sorted(["y","e","n","n","e","r"]):
47+
print(i)
48+
49+
for i,e in enumerate(sorted(["y","e","n","n","e","r"])):
50+
print(f"Indice: {i}, valor: {e}")
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
conjuntos
3+
"""
4+
my_set = {2,3,4,5,6}
5+
my_set.add(7) # Añadir elemento al final
6+
print(f"A1{my_set}")
7+
new_element = 1
8+
my_new_set = {new_element, *my_set} # Añadir elemento al inicio
9+
print(f"A2{my_new_set}")
10+
new_elements = {8,9,10}
11+
my_new_set.update(new_elements)
12+
print(f"A3{my_new_set}") #Añadir varios elementos en bloque al final
13+
14+
"""
15+
En Python, los sets no tienen un orden específico de elementos, por lo que técnicamente no puedes
16+
agregar elementos en una posición concreta como podrías hacer con una lista o una tupla
17+
"""
18+
19+
"""
20+
No puedo acceder a una posición, pero puedo eliminar el elemento único
21+
"""
22+
my_new_set.remove(6)
23+
print(f"A5{my_new_set}") # Eliminar elemento unico
24+
25+
"""
26+
En un set no se puede actualizar un elemento ya que trabaja con elementos unicos
27+
"""
28+
print(f"A6",10 in my_new_set) # Comprobar si el elemento está en el conjunto
29+
30+
my_new_set.clear()
31+
print(f"A7 Contenido eliminado {my_new_set}") #Eliminar todo el contenido del conjunto
32+
33+
34+
"""
35+
Ejercicio
36+
"""
37+
38+
my_set1 = {1,2,3,4}
39+
my_set2 = {4,5,6}
40+
41+
union_set = my_set1.union(my_set2)
42+
print(f"Esta es la unión de los dos conjuntos {union_set}") #Unión
43+
44+
intersection_set = my_set1.intersection(my_set2)
45+
print(f"Esta es la intersección de los dos conjuntos {intersection_set}") #Intersección
46+
47+
difference_set = my_set1.difference(my_set2)
48+
print(f"Esta es la diferencia de los dos conjuntos {difference_set}") #Diferencia
49+
50+
simetry_difference = my_set1.symmetric_difference(my_set2)
51+
print(f"Esta es la diferencia simetrica de los dos conjuntos {simetry_difference}") #Diferencia simetrica
52+

0 commit comments

Comments
 (0)