Introducci贸n

1

El Zen de Python

Conjuntos

2

Sets

3

Modificando conjuntos

4

Operaciones con conjuntos

5

Playgrounds: Elimina elementos duplicados usando conjuntos

Comprehensions

6

List Comprehension

7

Dictionary Comprehension

8

Dictionary Comprehension: condition

9

Playgrounds: Crea una lista usando List Comprehension

10

Lists vs. Tuples vs. Sets

Funciones

11

Funciones

12

Funciones: return

13

Par谩metros por defecto y m煤ltiples returns

14

El scope

15

Refactor game

16

Playgrounds: Tienda de Tecnolog铆a

17

Funciones an贸nimas: lambda

18

Higher order function: una funci贸n dentro de otra funci贸n

19

Map

20

Map con diccionarios

21

Reto: map con inmutabilidad

22

Playgrounds: Multiplica todos los elementos por dos

23

Filter

24

Playgrounds: Retorna solo palabras de 4 letras y m谩s

25

Reduce

M贸dulos

26

M贸dulos

27

Mis propios m贸dulos

28

M贸dulos como scripts: __name__ y __main__

29

Paquetes

30

Playgrounds: Calcular la suma de todas las compras

Manipulaci贸n de archivos y errores

31

Iterables

32

Errores en Python

33

Manejo de excepciones

34

Playgrounds: Captura la excepci贸n: ZeroDivisionError

35

Leer un archivo de texto

36

Escribir en un archivo

37

Leer un CSV

38

Playgrounds: Lee un CSV para calcular el total de gastos

Gr谩ficas en Python

39

Creando una gr谩fica

40

Reto: graficando la poblaci贸n de un pa铆s

41

Reto: graficando la poblaci贸n mundial

Pr贸ximos pasos

42

隆Conoce otros proyectos de este curso!

43

Reconoce tu proceso y certif铆cate

44

Toma el Curso de PIP y Entornos Virtuales con Python

No tienes acceso a esta clase

隆Contin煤a aprendiendo! 脷nete y comienza a potenciar tu carrera

Playgrounds: Elimina elementos duplicados usando conjuntos

5/44

Aportes 368

Preguntas 5

Ordenar por:

驴Quieres ver m谩s aportes, preguntas y respuestas de la comunidad?

o inicia sesi贸n.

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = countries.union(northAm,centralAm,southAm)

Escribe tu soluci贸n 馃憞

print(new_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁
new_set = countries | northAm | centralAm | southAm
print(new_set)

Escribe tu soluci贸n 馃憞

new_set = countries.union(northAm, centralAm, southAm)

new_set.update(countries, northAm, centralAm, southAm)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = set()
conjuntos = [countries,northAm,centralAm,southAm]

for lista in conjuntos:
new_set = new_set.union(lista)

print(new_set)

Profe usted en un comentario dijo que no habia que usar union. Pero usando union da bien el resultado ya que con hacer una union ya por defecto de la propiedad de conjunto no quedaria ningun repetido en el conjunto 驴supongo que lo decis por un tema de que le toma mas tiempo procesarlo si hacemos uniones? osea en un caso de 1248912 valores por ejemplo ahi afectaria?

Les dejo mi respuesta, lo hice sin mirar la respuesta de los dem谩s y lo razone con los apuntes que me hice en replit
result= (countries | northAm | centralAm | southAm)
new_set = set(result)
print(new_set)

As铆 fue mi soluci贸n 馃挌

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
new_set = countries | northAm | centralAm | southAm

print(new_set)

Bastante sencillo!

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = set()

Escribe tu soluci贸n 馃憞

new_set = countries | northAm | centralAm | southAm
print(new_set)

new_set = countries.union(northAm,centralAm,southAm)

No me sale el enunciado de la pr谩ctica. 馃槮

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = countries | northAm | centralAm | southAm

print(new_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = (countries|northAm|centralAm|southAm)
print (new_set)

mi respuesta ![](https://static.platzi.com/media/user_upload/Captura%20desde%202023-12-03%2012-15-46-cd6b589c-d04f-432c-99b1-1693486c5126.jpg)
Les dejo mi soluci贸n: countries = {"MX", "COL", "ARG", "USA"} northAm = {"USA", "CANADA"} centralAm = {"MX", "GT", "BZ"} southAm = {"COL", "BZ", "ARG"} new\_set = countries.union(northAm, centralAm, southAm)# Escribe tu soluci贸n 馃憞 print(new\_set)
```py new\_set = countries | northAm | centralAm | southAm ```
`Yo lo solucion茅 de esta forma.` ```js countries = {"MX", "COL", "ARG", "USA"} northAm = {"USA", "CANADA"} centralAm = {"MX", "GT", "BZ"} southAm = {"COL", "BZ", "ARG"} new_set = set() new_set= ((countries.union(northAm)).union(centralAm)).union(southAm) print(new_set) ```
new\_set = countries | northAm | centralAm | southAm
馃毃Alert Spoiler 馃毃 ![](https://static.platzi.com/media/user_upload/image-032f3ca7-4a52-4d6f-bc02-c89d3e16c213.jpg)
```js new_set0 = countries.union(northAm) new_set1 = countries.union(centralAm) new_set = countries.union(new_set0,new_set1) print(new_set) ```new\_set0 = countries.union(northAm)new\_set1 = countries.union(centralAm)new\_set = countries.union(new\_set0,new\_set1)print(new\_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = set(countries).union(northAm).union(centralAm).union(southAm)
print(new_set)

new\_set = countries.union(northAm).union(centralAm).union(southAm)print(new\_set)

Beneficios de empezar un set con conjunto vacio:
Iniciar con un conjunto vac铆o y luego actualizarlo con elementos de otros conjuntos es una pr谩ctica com煤n y tiene varias razones:

  1. Evitar Duplicados:

    • Al iniciar con un conjunto vac铆o, te aseguras de que no haya duplicados involuntarios. Si tienes un conjunto inicial con algunos elementos y luego actualizas con otro conjunto que contiene elementos ya presentes, se eliminar谩n autom谩ticamente los duplicados.
  2. Flexibilidad:

    • Iniciar con un conjunto vac铆o proporciona flexibilidad. Puedes decidir m谩s tarde qu茅 conjuntos agregar al conjunto vac铆o sin preocuparte por duplicados o elementos no deseados.
  3. Consistencia:

    • Iniciar con un conjunto vac铆o hace que el c贸digo sea consistente cuando trabajas con conjuntos m谩s grandes o si deseas realizar actualizaciones en varias etapas. La misma l贸gica se aplica incluso si est谩s agregando elementos uno por uno.
all_countries = set()  # Conjunto vac铆o

# Actualizar con elementos uno por uno
all_countries.update(["MX"])
all_countries.update(["USA", "CANADA"])
all_countries.update(["COL", "BZ", "ARG"])

En resumen, iniciar con un conjunto vac铆o proporciona una base limpia y evita problemas potenciales relacionados con duplicados, al tiempo que ofrece flexibilidad y consistencia en el manejo de conjuntos en tu c贸digo.

Soluci贸n propuesta:

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}
new_set = countries | northAm | centralAm | southAm
print(new_set)
countries = {"MX", "COL", "ARG", "USA"}northAm = {"USA", "CANADA"}centralAm = {"MX", "GT", "BZ"}southAm = {"COL", "BZ", "ARG"} new\_set = set()# Escribe tu soluci贸n 馃憞new\_set=countries|northAm|centralAm|southAmprint(new\_set)
import itertools countries = {"MX", "COL", "ARG", "USA"} northAm = {"USA", "CANADA"} centralAm = {"MX", "GT", "BZ"} southAm = {"COL", "BZ", "ARG"} new\_set = itertools.chain( countries, northAm, centralAm, southAm ) \# Escribe tu soluci贸n 馃憞 print(set(new\_set))
Para eliminar los elemeentos repetidos se utiliza diferencia simetrica, esto fue lo que realice: ```js countries = {"MX", "COL", "ARG", "USA"} northAm = {"USA", "CANADA"} centralAm = {"MX", "GT", "BZ"} southAm = {"COL", "BZ", "ARG"} new_set = set() # Escribe tu soluci贸n 馃憞 new_set1 = countries.symmetric_difference(northAm) new_set2 = centralAm.symmetric_difference(southAm) new_set = new_set1.symmetric_difference(new_set2) print(new_set) ```countries = {"MX", "COL", "ARG", "USA"}northAm = {"USA", "CANADA"}centralAm = {"MX", "GT", "BZ"}southAm = {"COL", "BZ", "ARG"} new\_set = set()# Escribe tu soluci贸n 馃憞new\_set1 = countries.symmetric\_difference(northAm)new\_set2 = centralAm.symmetric\_difference(southAm)new\_set = new\_set1.symmetric\_difference(new\_set2)print(new\_set)
EL m铆o. Lo logr茅 pero creo que est谩 largo el c贸digo en comparaci贸n con las soluciones de los dem谩s :C En mi no corri贸 la soluci贸n de unir todo de una vez:C ![](https://static.platzi.com/media/user_upload/Soluci%C3%B3n%20ejercicio%201-1b9deb19-f8da-4942-9e23-b320df00b8f9.jpg)
```python countries = {"MX", "COL", "ARG", "USA"} northAm = {"USA", "CANADA"} centralAm = {"MX", "GT", "BZ"} southAm = {"COL", "BZ", "ARG"} # Escribe tu soluci贸n 馃憞 new_set = countries | northAm | centralAm | southAm print(new_set) ```

Ac谩 dejo mi soluci贸n, recuerda que muchos son los caminos que conducen a una misma respuesta.

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()

join_sets = countries | northAm | centralAm | southAm;

new_set.update(join_sets);

print(new_set)
print(countries | northAm | centralAm | southAm)
new\_set = set(countries | northAm | centralAm | southAm)

Este ejercicio me gusto porque puse a prueba mis conocimientos como programador de python que estoy iniciando. Espero seguir asi para ser uno de los mejores.

new_set = countries.union(northAm).union(centralAm).union(southAm)

Lo hice de esta manera. print(countries | northAm | centralAm | southAm)
![](https://static.platzi.com/media/user_upload/image-32866e9a-ca5b-4e7d-8fa8-36f53039da59.jpg) Ejercicio Resuelto

Mi soluci贸n

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
# Escribe tu soluci贸n 馃憞
new_set = new_set.union(countries, northAm, centralAm, southAm)

print(new_set)

En estecaso la respuesta a la pregunta
new_set = set( countries | northAm | centralAm | southAm)

![](https://static.platzi.com/media/user_upload/image-a3a28100-949e-441e-9a04-abac2060d7f1.jpg)![](https://static.platzi.com/media/user_upload/image-46d84ef9-19fc-4a44-aec4-d94e64506036.jpg)
mi soluci贸n de acuerdo a la 煤ltima clase: countries = {"MX", "COL", "ARG", "USA"}northAm = {"USA", "CANADA"}centralAm = {"MX", "GT", "BZ"}southAm = {"COL", "BZ", "ARG"} new\_set = set()# Escribe tu soluci贸n 馃憞new\_set = countries | northAm | centralAm | southAm print(new\_set)
<countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}


new_set = countries.union(northAm, centralAm, southAm)

print(new_set)
>
`countries = {"MX", "COL", "ARG", "USA"}` `northAm = {"USA", "CANADA"}` `centralAm = {"MX", "GT", "BZ"}` `southAm = {"COL", "BZ", "ARG"}` `new_set = set()` `#soluci贸n 馃憞 ` `new_set=countries.union(northAm).union(centralAm).union(southAm)` `print(new_set)`
countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set(countries.union(northAm,centralAm,southAm))
# Escribe tu soluci贸n 馃憞

print(new_set)
![](https://static.platzi.com/media/user_upload/image-c0b274e1-e3f3-4191-8543-7fd4c9d36b90.jpg)
Cual seria mas rapida o mas recomendable?: * new\_set.update(countries, northAm, centralAm, southAm) * new\_set = countries | northAm | centralAm | southAm
countries = {"MX", "COL", "ARG", "USA"} northAm = {"USA", "CANADA"} centralAm = {"MX", "GT", "BZ"} southAm = {"COL", "BZ", "ARG"} new\_set = set() new\_set = countries | northAm | centralAm | southAm print(new\_set)
```python new_set = countries.union(northAm, centralAm,southAm) ```

Resolv铆 el ejercicio utilizando el operador de unpacking " * " xp.

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = {*countries, *northAm, *centralAm, *southAm}
# Escribe tu soluci贸n 馃憞

print(new_set)

reto solucionado

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}


# Escribe tu soluci贸n 馃憞
new_set = countries | northAm | centralAm | southAm

print(new_set)```
![](https://static.platzi.com/media/user_upload/image-8938bd84-cac8-453d-aaab-938856002788.jpg)
new\_set = countries.union(northAm,centralAm,southAm)print(new\_set)
a = countries.union(northAm)b = centralAm.union(southAm)new\_set = a.union(b)print(new\_set)
new\_set = set(countries.union(northAm, centralAm, southAm))
new\_set = countries.union(northAm, centralAm, southAm) ```python new_set = countries.union(northAm, centralAm, southAm) ``` ```js ```

Mi soluci贸n:

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
# Escribe tu soluci贸n 馃憞
new_set = countries.union(northAm, centralAm, southAm)
print(new_set)

Seguramente alguien novato como yo, lo hizo de esta forma, pensando que no se pueden hacer operaciones con m谩s de dos conjuntos

union_1 = countries.union(northAm)
union_2 = centralAm.union(southAm)
new_set = set(union_1.union(union_2))
print(new_set)
countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set(countries | northAm | centralAm | southAm)
# Escribe tu soluci贸n 馃憞


print(new_set)

new_set = countries | northAm | centralAm | southAm

new_set = countries | northAm |centralAm|southAm

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = set()

Escribe tu soluci贸n 馃憞

new_set = countries.union(northAm, centralAm, southAm)
print(new_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = set()

Escribe tu soluci贸n 馃憞

new_set = countries.union(northAm,centralAm,southAm)
print(new_set)

countries = {鈥淢EX鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
nortAmerica = {鈥淯SA鈥, 鈥淐AN鈥潁
centralAmerica = {鈥淢EX鈥, 鈥淕UA鈥, 鈥淧UE鈥潁
southAmerica = {鈥淐OL鈥, 鈥淏RA鈥, 鈥淎RG鈥潁

newSet = countries|nortAmerica|centralAmerica|southAmerica
print(newSet)

Aqu铆 mi soluci贸n, very easy.

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = countries.union(northAm, centralAm, southAm)
# Escribe tu soluci贸n 馃憞

print(new_set)
new_set = countries | northAm | centralAm | southAm

Union si es la operaci贸n correcta , recuerda que los conjuntos no pueden tener elementos duplicados, as铆 que al hacer uni贸n, los elementos duplicados se eliminan y da el resultado correcto.

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = set()
new_set = countries.union(northAm, centralAm, southAm)

print(new_set)

Algo sencillo pero aqui esta.

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}
new_set = set(countries | northAm | centralAm | southAm)
# 馃憞
print(new_set)

Soluci贸n al reto:

La linea de c贸digo utilizada para mi soluci贸n fue la siguiente:

new_set = countries | northAm | centralAm | southAm

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = countries.union(northAm.union(centralAm.union(southAm)))

Escribe tu soluci贸n 馃憞

print(new_set)

Realiza este ejercicio con la Union
countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = northAm.union(centralAm,southAm)
print(new_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = countries.union(northAm, centralAm, southAm)

print(new_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

set_total = countries.union(northAm, centralAm, southAm)
new_set = set(set_total)

Escribe tu soluci贸n 馃憞

print(new_set)

Hola 馃槂

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set(countries | northAm | centralAm | southAm )  


print(new_set)

Un detalle a tener en cuenta, al aplicar set.union, esto afecta directamente al conjunto(set). Es un m茅todo que actualiza al conjunto sobre el que se aplica, por tanto no genera un nuevo conjunto y no puede ser almacenado en una variable. Por ejemplo, no podemos hacer esto:

set_c = set_a.union(set_b)
print(set_c)	---> Nos arroja "None". Es incorrecto

Si queremos mostrar el resultado de dicha union, debemos seleccionar set_a. Ya que union modific贸 directamente dicho conjunto. O a su vez igualarlo a otro conjunto si queremos expresarlo en uno diferente. Por ejemplo:

set_a.union(set_b)
print(set_a)	---> Es correcto

set_c = set_a
countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
# Escribe tu soluci贸n 馃憞
new_set = countries | northAm | centralAm | southAm

print(new_set)

countries = {鈥淢X鈥, 鈥淐OL鈥, 鈥淎RG鈥, 鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁

new_set = countries.union(northAm, centralAm, southAm)

print(new_set)

Pues estuvo f谩cil, solo me demore por no leer bien el enunciado 馃槤, aqu铆 la soluci贸n que he encontrado:


.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = countries | northAm | centralAm | southAm

print(new_set)

Comparto mi soluci贸n

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
# Escribe tu soluci贸n 馃憞
new_set = new_set.union(countries,northAm,centralAm,southAm)
print(new_set)

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
# Escribe tu soluci贸n 馃憞
new_set = countries | northAm | centralAm | southAm
print(new_set)
<code>
countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set(countries | northAm | centralAm | southAm)
# Escribe tu soluci贸n 馃憞

print(new_set)
 

keep it simple

Listo!

countries = {鈥淢X鈥,鈥淐OL鈥,鈥淎RG鈥,鈥淯SA鈥潁
northAm = {鈥淯SA鈥, 鈥淐ANADA鈥潁
centralAm = {鈥淢X鈥, 鈥淕T鈥, 鈥淏Z鈥潁
southAm = {鈥淐OL鈥, 鈥淏Z鈥, 鈥淎RG鈥潁
new_set = set(countries | northAm | centralAm | southAm)
print(new_set)


.
.
.
.
.
.

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()

new_set = countries | northAm | centralAm | southAm

print(new_set)

Aqu铆 mi soluci贸n, solo que no entiendo bien que hace set(), es una l铆nea de c贸digo para despistarnos XD

Soluci贸n

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = countries.union(northAm, centralAm, southAm)
# Escribe tu soluci贸n 馃憞

print(new_set)

Cada vez que logro completar el desaf铆o sin pistas, ni ayuda, sino por mi propia cuenta, siento que doy un paso m谩s en el aprendizaje de Python :鈥)

new_set = set(countries | northAm | centralAm | southAm)

Tambien funciona con update:

countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = set()
# Escribe tu soluci贸n 馃憞
new_set.update(countries, northAm, centralAm, southAm)

print(new_set)
 

鉂孲POILER ALERT 鉂




countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = countries | northAm | centralAm | southAm


print(new_set)

hola dejo mi resultado

<countries = {"MX", "COL", "ARG", "USA"}
northAm = {"USA", "CANADA"}
centralAm = {"MX", "GT", "BZ"}
southAm = {"COL", "BZ", "ARG"}

new_set = countries.union(northAm,centralAm,southAm)
print(new_set)
> 
undefined