Este taller es para resolver problemas básicos de python. Manejo de listas, diccionarios, etc.
El taller debe ser realizado en un Notebook de Jupyter en la carpeta de cada uno. Debe haber commits con el avance del taller. Debajo de cada pregunta hay una celda para el código.
In [2]:
import platform
platform.python_version()
Out[2]:
In [7]:
r=5
area=3.14*r**2
print (area)
In [1]:
color_list_1 = set(["White", "Black", "Red"])
color_list_2 = set(["Red", "Green"])
In [5]:
print (color_list_1 - color_list_2)
In [11]:
import os
s=os.getcwd()
lista= s.split('\\')
print ('Donde se ejecuta: '+ s )
print (lista[1])
print (lista[2])
print (lista[3])
print (lista[4])
In [7]:
my_list = [5,7,8,9,17]
In [9]:
sum=0
for i in my_list:
sum=sum+i
print (sum)
In [3]:
elemento_a_insertar = 'E'
my_list = [1, 2, 3, 4]
La salida esperada es una lista así: [E, 1, E, 2, E, 3, E, 4]
In [13]:
elemento_a_insertar = 'E'
my_list = [1, 2, 3, 4]
index=-2
while index<6:
index=index+2
my_list.insert(index, elemento_a_insertar)
print (my_list)
In [17]:
N = 3
my_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n']
Salida Epserada: [['a', 'd', 'g', 'j', 'm'], ['b', 'e', 'h', 'k', 'n'], ['c', 'f', 'i', 'l']]
In [18]:
new_list = [[] for _ in range(N)]
for i, item in enumerate(my_list):
new_list[i % N].append(item)
print (new_list)
In [22]:
list_of_lists = [ [1,2,3], [4,5,6], [10,11,12], [7,8,9] ]
Salida Esperada: [10, 11, 12]
In [23]:
print (max(list_of_lists))
In [8]:
N = 5
Salida Esperada: {1:1, 2:4, 3:9, 4:16, 5:25}
In [24]:
d = {}
N=5
i=0
while i < N:
i=i+1
d[i]=i**2
print (d)
In [7]:
dictionary_list=[{1:10, 2:20} , {3:30, 4:40}, {5:50,6:60}]
Salida Esperada: {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60}
In [2]:
dictionary_list=[{1:10, 2:20} ,
{3:30, 4:40},
{5:50,6:60}]
new_dic={}
for i in range(len(dictionary_list)):
new_dic.update(dictionary_list[i])
print (new_dic)
In [25]:
dictionary_list=[{'numero': 10, 'cantidad': 5} , {'numero': 12, 'cantidad': 3}, {'numero': 5, 'cantidad': 45}]
Salida Esperada: [{'numero': 10, 'cantidad': 5, 'cuadrado': 100} , {'numero': 12, 'cantidad': 3, , 'cuadrado': 144}, {'numero': 5, 'cantidad': 45, , 'cuadrado': 25}]
In [5]:
dictionary_list=[{'numero': 10, 'cantidad': 5} ,
{'numero': 12, 'cantidad': 3},
{'numero': 5, 'cantidad': 45}]
for i in range(len(dictionary_list)):
a= dictionary_list[i]['numero']
sq=a**2
dictionary_list[i]['cuadrado']= sq
print (dictionary_list)
In [6]:
def inter(list1,list2):
print (list1 - list2)
list1=set([1,2,3])
list2=set([1,4,5])
inter(list1,list2)
In [8]:
def max_ll(list_of_lists):
print (max(list_of_lists))
list_of_lists = [ [1,212,3321], [4,25,6123], [1,11,1122], [7,85,9] ]
max_ll(list_of_lists)
In [9]:
def lis_sqr(N):
d = {}
i=0
while i < N:
i=i+1
d[i]=i**i
print (d)
lis_sqr(4)
In [ ]: