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 458: Crear un objeto deque e iterar su contenido con un ciclo for. | |
from collections import deque | |
d = deque('aeiou') | |
for v in d: | |
print(v) |
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 457: Hallar los elementos más comunes y el número de ocurrencias en una colección. | |
from collections import Counter | |
frase = 'Python es un lenguaje de programación. Python versión 3.8.1. Python es uno de los lenguajes más utilizados para crear soluciones de software.' | |
contador = Counter(frase) | |
print(contador) |
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 456: Repetir un elemento cierta cantidad de veces con la clase Counter. | |
from collections import Counter | |
contador = Counter(a=5, e=4, i=0, o=-1, u=2) | |
print(contador) | |
print() | |
elementos_repetidos = list(contador.elements()) |
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 455: Filtrar los elementos de un objeto conjunto con la función filter(). | |
numeros = set([2, 3, 5, 7, 11, 13, 17, 19]) | |
print(len(numeros)) | |
print(numeros) | |
print() | |
resultado = set(filter(lambda e: e > 7, numeros)) |
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 454: Encontrar los valores mínimo y máximo en un objeto conjunto. | |
numeros = set([13, 2, 19, 7, 5, 11, 3]) | |
print(numeros) | |
minimo = min(numeros) | |
print(minimo) | |
maximo = max(numeros) |
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 453: Comprobar si dos conjuntos no tienen elementos en común con isdisjoint(). | |
colores_1 = set(['Negro', 'Blanco']) | |
colores_2 = set(['Azul', 'Rojo', 'Negro']) | |
colores_3 = set(['Gris']) | |
print(colores_1) | |
print(colores_2) | |
print(colores_3) |
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 452: Remover todos los elementos de un conjunto con el método de instancia clear(). | |
numeros = set([2, 3, 5, 7]) | |
print(len(numeros)) | |
print(numeros) | |
print() | |
numeros.clear() |
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 451: Crear una copia de todos los elementos de un objeto conjunto. | |
numeros = set([2, 3, 5, 7]) | |
print(numeros) | |
numeros_copia = numeros.copy() | |
print(numeros_copia) | |
print(numeros_copia is numeros) |
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 450: Comprobar si un conjunto es subconjunto o superconjunto de otro conjunto. | |
colores_1 = set(['Negro', 'Blanco']) | |
colores_2 = set(['Blanco', 'Rojo']) | |
colores_3 = set(['Blanco']) | |
print(colores_1) | |
print(colores_2) | |
print(colores_3) |
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 449: Calcular la diferencia simétrica entre dos objetos conjunto. | |
# ^ | |
colores_1 = set(['Negro', 'Rojo']) | |
colores_2 = set(['Rojo', 'Blanco']) | |
print(colores_1) | |
print(colores_2) |