my_list = [i**2 for i in range(0,101,1)]
my_list_2 = [i**2 for i in range(0, 11, 1) if i % 3 != 0]
my_list_2
my_list_3 = [i for i in range(0, 100000, 1) if (i % 4 == 0 and i % 6 == 0 and i % 9 == 0)]
def run():
dict_1 = {i: i**3 for i in range(1, 101)}
print(dict_1)
if __name__ == '__main__':
run()
def run():
dict_1 = {i: i**3 for i in range(1, 101) if i % 3 != 0}
print(dict_1)
if __name__ == '__main__':
run()
def run():
dict_2 = {i: round(i**(1/2), 2) for i in range(1, 1001)}
print(dict_2)
if __name__ == '__main__':
run()
palindrome = lambda string: string == string[::-1]
palindrome("ana")
# Remover los números pares con list comprehension
l = [1, 4, 5, 6, 9, 13, 19, 21]
[ i for i in l if i % 2 != 0]
# Ahora con filter
l2 = list(filter(lambda x: x%2 != 0, l))
l2
# Elevar al cuadrado los elementos con list comprehensions
l3 = [1, 2, 3, 4, 5]
l4 = [i**2 for i in l3]
l4
# Ahora con map
l5 = list(map(lambda x: x**2, l3))
l5
l6 = [2, 2, 2, 2, 2]
all_multiplied = 1
for i in l6:
all_multiplied *= i
print(all_multiplied)
# Ahora con reduce
from functools import reduce
reduced = reduce(lambda a, b: a*b, l6)
print(reduced)
DATA = [
{
'name': 'Facundo',
'age': 72,
'organization': 'Platzi',
'position': 'Technical Coach',
'language': 'python',
},
{
'name': 'Luisana',
'age': 33,
'organization': 'Globant',
'position': 'UX Designer',
'language': 'javascript',
},
{
'name': 'Héctor',
'age': 19,
'organization': 'Platzi',
'position': 'Associate',
'language': 'ruby',
},
{
'name': 'Gabriel',
'age': 20,
'organization': 'Platzi',
'position': 'Associate',
'language': 'javascript',
},
{
'name': 'Isabella',
'age': 30,
'organization': 'Platzi',
'position': 'QA Manager',
'language': 'java',
},
{
'name': 'Karo',
'age': 23,
'organization': 'Everis',
'position': 'Backend Developer',
'language': 'python',
},
{
'name': 'Ariel',
'age': 32,
'organization': 'Rappi',
'position': 'Support',
'language': '',
},
{
'name': 'Juan',
'age': 17,
'organization': '',
'position': 'Student',
'language': 'go',
},
{
'name': 'Pablo',
'age': 32,
'organization': 'Master',
'position': 'Human Resources Manager',
'language': 'python',
},
{
'name': 'Lorena',
'age': 56,
'organization': 'Python Organization',
'position': 'Language Maker',
'language': 'python',
},
]
def run():
all_py_devs = [worker["name"] for worker in DATA if worker['language'] == "python"]
all_platzi_workers = [worker["name"] for worker in DATA if worker["organization"] == "Platzi"]
adults = list(filter(lambda worker: worker["age"] > 18, DATA))
adults = list(map(lambda worker: worker["name"], adults))
# | símbolo pipe: une un diccionario con otro nuevo.
old = list(map(lambda worker: worker | {"old": worker['age'] > 70}, DATA))
# ALTERNATIVA PARA VERSIONES ANTERIORES A 3.9:
# old_people = list(map(lambda worker: {**worker, **{"old": worker["age"] > 70}}, DATA))
for worker in old:
print(worker)
if __name__ == '__main__':
run()
all_py_devs = list(filter(lambda worker: worker['language'] == 'python', DATA))
all_py_devs = list(map(lambda worker: worker['name'], all_py_devs))
all_py_devs
all_platzi_workers = list(filter(lambda worker: worker['organization'] == 'Platzi', DATA))
all_platzi_workers = list(map(lambda worker: worker['name'], all_platzi_workers))
all_platzi_workers
adults = [worker['name'] for worker in DATA if worker['age']> 18]
adults
old_confirmation = lambda worker_age: worker_age > 70
old_people = [worker | {'old': old_confirmation(worker['age'])} for worker in DATA]
try:
<bloque1>
except <error> as <alias>:
<bloque 2>
raise <NombreError>("<descripci[on del error>")
def palindrome(string):
assert len(string) > 0, "No se puede ingresar una cadena vacía."
return string == string[::-1]
print(palindrome(""))
def divisors(num):
divisors = [i for i in range(1, num+1) if num % i == 0]
return divisors
def run():
num = input("Ingresa un número: ")
assert num.isnumeric(), "Debes ingresar un número positivo" # .isnumeric devuelve True o False
print(divisors(int(num)))
print("End")
if __name__ == '__main__':
run()