This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 448: Calcular la diferencia entre dos objetos conjunto con el operador diferencia. | |
# - | |
colores_1 = set(['Negro', 'Blanco', 'Rojo']) | |
colores_2 = set(['Blanco', 'Negro', 'Azul', 'Gris']) | |
print(colores_1) | |
print(colores_2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 447: Computar el conjunto unión entre dos objetos conjunto. | |
colores_1 = set(['Negro', 'Blanco', 'Rojo']) | |
colores_2 = set(['Azul', 'Verde', 'Gris', 'Negro']) | |
print(colores_1) | |
print(colores_2) | |
print() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 446: Hallar los elementos comunes de dos conjuntos con el operador intersección. | |
# & | |
colores_1 = set(['Negro', 'Blanco', 'Azul']) | |
colores_2 = set(['Rojo', 'Verde', 'Azul', 'Amarillo', 'Negro']) | |
print(colores_1) | |
print(colores_2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 445: Remover un elemento de un conjunto si está disponible con el método discard(). | |
numeros = set([2, 3, 5, 7, 11, 13]) | |
print(len(numeros)) | |
print(numeros) | |
print() | |
numeros.discard(7) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 444: Remover elementos de un objeto conjunto con el método de instancia pop(). | |
numeros = set([2, 3, 5, 7, 11]) | |
print(len(numeros)) | |
print(numeros) | |
print() | |
numero = numeros.pop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 443: Agregar múltiples elementos a un objeto conjunto con el método update(). | |
colores = set() | |
colores.add('Negro') | |
colores.add('Blanco') | |
print(len(colores)) | |
print(colores) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 442: Agregar elementos a un objeto conjunto con el método de instancia add(). | |
lenguajes = set() | |
print(len(lenguajes)) | |
print(lenguajes) | |
print() | |
lenguajes.add('Python') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 441: Iterar todos los elementos contenidos en un objeto conjunto. | |
numeros = {0, 1, 1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9} | |
print(type(numeros)) | |
print(len(numeros)) | |
print(numeros) | |
print() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 440: Crear un conjunto utilizando la literal de conjunto y la clase set. | |
# Literal de conjunto: | |
conjunto_literal = {0, 1, 2, 2, 3, 4, 5, 5, 5, 5, 5} | |
print(type(conjunto_literal)) | |
print(len(conjunto_literal)) | |
print(conjunto_literal) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ejercicio 439: Orden descendente una lista de tuplas por el valor de punto flotante de cada tupla. | |
productos = [('Mouse', '29.5'), ('Teclado', '77.9'), ('Auriculares', '15.9'), ('Deademas', '49.9')] | |
print(productos) | |
resultado = sorted(productos, key=lambda p: float(p[1]), reverse=True) | |
print(resultado) |