Skip to content

Commit 15e81b6

Browse files
authored
Merge pull request #6653 from mikelm2020/miguellopezmdev
Miguellopezmdev
2 parents a5f5409 + 5dc50ca commit 15e81b6

File tree

2 files changed

+291
-0
lines changed

2 files changed

+291
-0
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Ejercicio
2+
from functools import reduce
3+
from itertools import count, islice
4+
5+
6+
def iteration_with_for():
7+
for index in range(1, 11):
8+
print(index)
9+
10+
11+
def iteration_with_while():
12+
index = 1
13+
while index <= 10:
14+
print(index)
15+
index += 1
16+
17+
18+
def iteration_with_for_in():
19+
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
20+
for index in array:
21+
print(index)
22+
23+
24+
# Extra
25+
def iteration_with_for_each():
26+
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
27+
for element in array:
28+
print(element)
29+
30+
31+
def recursive_count(number=1):
32+
if number <= 10:
33+
print(number)
34+
recursive_count(number + 1)
35+
36+
37+
def iteration_with_comprehension():
38+
print(*[index for index in range(1, 11)], sep="\n")
39+
40+
41+
def iteration_with_map():
42+
print(*map(lambda x: x, range(1, 11)))
43+
44+
45+
def iteration_with_filter():
46+
print(*filter(lambda x: True if x <= 10 else False, range(1, 101)))
47+
48+
49+
def iteration_with_reduce():
50+
print(reduce(lambda x, y: x + y, range(1, 11)))
51+
52+
53+
def iteration_with_islice():
54+
print(*islice(count(1), 10))
55+
56+
57+
def iteration_with_zip():
58+
print(*zip(range(1, 11), range(11, 21)))
59+
60+
61+
def iteration_with_enumerate():
62+
print(*enumerate([x for x in range(1, 11)], 1))
63+
64+
65+
def iteration_with_comprehension_2():
66+
print(*[(x, y) for x in range(1, 11) for y in range(x, 11)])
67+
68+
69+
def iteration_with_comprehension_3():
70+
print(*[(x, y) for x in range(1, 11) for y in range(x, 11) if x != y])
71+
72+
73+
def iteration_with_comprehension_4():
74+
print(
75+
*[
76+
(x, y, z)
77+
for x in range(1, 11)
78+
for y in range(x, 11)
79+
for z in range(y, 11)
80+
if x != y != z
81+
]
82+
)
83+
84+
85+
def iteration_with_comprehension_5():
86+
print(
87+
*[
88+
(x, y, z)
89+
for x in range(1, 11)
90+
for y in range(x, 11)
91+
for z in range(y, 11)
92+
if x != y != z and x < y < z
93+
]
94+
)
95+
96+
97+
def iteration_with_comprehension_6():
98+
print(
99+
*[
100+
(x, y, z)
101+
for x in range(1, 11)
102+
for y in range(x, 11)
103+
for z in range(y, 11)
104+
if x != y != z and x > y > z
105+
]
106+
)
107+
108+
109+
def iteration_with_comprehension_7():
110+
print(
111+
*[
112+
(x, y, z)
113+
for x in range(1, 11)
114+
for y in range(x, 11)
115+
for z in range(y, 11)
116+
if x != y != z and x == y == z
117+
]
118+
)
119+
120+
121+
def iteration_with_comprehension_8():
122+
print(
123+
*[
124+
(x, y, z)
125+
for x in range(1, 11)
126+
for y in range(x, 11)
127+
for z in range(y, 11)
128+
if x != y != z and x < y > z
129+
]
130+
)
131+
132+
133+
def iteration_with_comprehension_9():
134+
print(
135+
*[
136+
(x, y, z)
137+
for x in range(1, 11)
138+
for y in range(x, 11)
139+
for z in range(y, 11)
140+
if x != y != z and x > y < z
141+
]
142+
)
143+
144+
145+
def iteration_with_comprehension_10():
146+
print(
147+
*[
148+
(x, y, z)
149+
for x in range(1, 11)
150+
for y in range(x, 11)
151+
for z in range(y, 11)
152+
if x != y != z and x < y == z
153+
]
154+
)
155+
156+
157+
def iteration_with_comprehension_11():
158+
print(
159+
*[
160+
(x, y, z)
161+
for x in range(1, 11)
162+
for y in range(x, 11)
163+
for z in range(y, 11)
164+
if x != y != z and x > y == z
165+
]
166+
)
167+
168+
169+
if __name__ == "__main__":
170+
print("Con For")
171+
iteration_with_for()
172+
print("Con While")
173+
iteration_with_while()
174+
print("Con For In")
175+
iteration_with_for_in()
176+
print("Con For Each")
177+
iteration_with_for_each()
178+
print("Con Recursividad")
179+
recursive_count()
180+
print("Con list comprehension")
181+
iteration_with_comprehension()
182+
print("Con Map")
183+
iteration_with_map()
184+
print("Con Filter")
185+
iteration_with_filter()
186+
print("Con Reduce")
187+
iteration_with_reduce()
188+
print("Con Islice")
189+
iteration_with_islice()
190+
print("Con Zip")
191+
iteration_with_zip()
192+
print("Con Enumerate")
193+
iteration_with_enumerate()
194+
print("Con Comprehension v2")
195+
iteration_with_comprehension_2()
196+
print("Con Comprehension v3")
197+
iteration_with_comprehension_3()
198+
print("Con Comprehension v4")
199+
iteration_with_comprehension_4()
200+
print("Con Comprehension v5")
201+
iteration_with_comprehension_5()
202+
print("Con Comprehension v6")
203+
iteration_with_comprehension_6()
204+
print("Con Comprehension v7")
205+
iteration_with_comprehension_7()
206+
print("Con Comprehension v8")
207+
iteration_with_comprehension_8()
208+
print("Con Comprehension v9")
209+
iteration_with_comprehension_9()
210+
print("Con Comprehension v10")
211+
iteration_with_comprehension_10()
212+
print("Con Comprehension v11")
213+
iteration_with_comprehension_11()
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
my_set = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
2+
3+
# ejercicio
4+
5+
print("Ejercio")
6+
print("Conjunto a trabajar")
7+
print(my_set)
8+
print("\nAñade un elemento al final, añadimos el 11")
9+
my_set.add(11)
10+
print(my_set)
11+
12+
print("\nAñade un elemento al principio, añadimos el 0")
13+
my_list = list(my_set)
14+
my_list.insert(0, 0)
15+
my_set = set(my_list)
16+
print(my_set)
17+
18+
print("\nAñade varios elementos en bloque al final, añadimos 13,14,15,16")
19+
my_list = [13, 14, 15, 16]
20+
my_set.update(my_list)
21+
print(my_set)
22+
23+
print("\nAñade varios elementos en bloque en una dirección concreta")
24+
print("Añadimos en la posición 2 los valores 17,18,19,20")
25+
my_list = list(my_set)
26+
print(f" El conjunto convertido en lista es {my_list}")
27+
my_list[2:4] = [17, 18, 19, 20]
28+
print(f" La lista con los elementos insertados es {my_list}")
29+
my_set = set(my_list)
30+
print("El conjunto resultante")
31+
print(my_set)
32+
33+
print("\nElimina un elemento en una posición concreta, eliminamos el de la posición 2")
34+
my_list = list(my_set)
35+
del my_list[2]
36+
my_set = set(my_list)
37+
print(my_set)
38+
39+
print(
40+
"\nActualiza el valor de un elemento en una dirección concreta, actualiazamos el de la posición 4"
41+
)
42+
my_list = list(my_set)
43+
my_list[4] = 35
44+
my_set = set(my_list)
45+
print(my_set)
46+
47+
print("\nComprueba si un elemento está en un conjunto, comprobamos si existe el 35")
48+
print(35 in my_set)
49+
50+
print("\nElimina todo el contenido del conjunto")
51+
my_set.clear()
52+
print(my_set)
53+
54+
55+
# Extra
56+
57+
my_set = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
58+
my_set2 = {4, 6, 7, 8, 12, 14, 16}
59+
60+
print("Dificultad extra")
61+
print("Conjuntos para trabajar")
62+
print(f" my_set = {my_set}")
63+
print(f" my_set2 = {my_set2}")
64+
print("\nUnión: ")
65+
union = my_set | my_set2
66+
print(union)
67+
68+
print("\nIntersección: ")
69+
interseccion = my_set & my_set2
70+
print(interseccion)
71+
72+
print("\nDiferencia: ")
73+
diferencia = my_set - my_set2
74+
print(diferencia)
75+
76+
print("\nDiferencia simétrica: ")
77+
simetric_difference = my_set ^ my_set2
78+
print(simetric_difference)

0 commit comments

Comments
 (0)