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 428: Remover un elemento de una tupla usando una lista. | |
numeros = (2, 3, 5, 7, 11) | |
numeros_lista = list(numeros) | |
print(numeros_lista) | |
numeros_lista.pop(2) | |
print(numeros_lista) |
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 427: Crear una funci贸n para remover un elemento de un objeto tupla. | |
def remover_elemento(tupla, i): | |
if 0 <= i < len(tupla): | |
return tupla[0:i] + tupla[i+1:] | |
raise ValueError('i est谩 por fuera del rango.') | |
numeros = (2, 3, 5, 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 426: Convertir un objeto lista en un objeto tupla con la clase tuple. | |
lista = list(range(1, 11)) | |
print(len(lista)) | |
print(type(lista)) | |
print(lista) | |
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 425: Comprobar si un elemento existe en un tupla por medio del operador in. | |
letras = ('P', 'y', 't', 'h', 'o', 'n') | |
print('y' in letras) | |
print('P' in letras) | |
print('p' in letras) | |
print('i' in letras) |
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 424: Contar el n煤mero de ocurrencias de un elemento en una tupla. | |
numeros = (2, 3, 2, 2, 5, 5, 3, 7, 11, 13, 13, 2, 19, 23) | |
print(numeros) | |
cantidad_dos = numeros.count(2) | |
print('El n煤mero 2 aparece {} veces.'.format(cantidad_dos)) |
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 423: Crear una copia de un objeto tupla usando notaci贸n slicing y la clase tuple. | |
numeros = (1, 2, 3, 4, 5) | |
print(numeros) | |
print() | |
# Slicing: | |
numeros_copia_1 = 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 422: Crear una tupla a partir de una tupla de comprensi贸n. | |
cuadrados = tuple(n**2 for n in range(1, 11)) | |
print(type(cuadrados)) | |
print(len(cuadrados)) | |
print(cuadrados) |
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 421: Convertir una tupla en una cadena de caracteres. | |
letras = ('P', 'y', 't', 'h', 'o', 'n') | |
python = ''.join(letras) | |
print(type(python)) | |
print(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 420: Convertir un objeto tupla en un objeto lista. | |
tupla = (1, 2, 3) | |
print(len(tupla)) | |
print(type(tupla)) | |
print(tupla) | |
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 419: Agregar elementos en una posici贸n intermedia de un objeto tupla. | |
def agregar_elementos(tupla, i, elementos): | |
if 0 < i < len(tupla) - 1: | |
return tupla[:i] + elementos + tupla[i:] | |
return None | |
numeros = (1, 2, 6, 7) |