Introducción a Python para finanzas
Adina Howe
Professor
prices.sort()type(prices)list.method()list.sort() ordena los elementos en orden ascendente
prices = [238.11, 237.81, 238.91]prices.sort()print(prices)
[237.81, 238.11, 238.91]
list.append() añade un único elemento a una lista
months = ['January', 'February', 'March']months.append('April')print(months)
['January', 'February', 'March', 'April']
list.extend() añade cada elemento de una secuencia
months.extend(['May', 'June', 'July'])print(months)
['January', 'February', 'March', 'April', 'May', 'June', 'July']
list.index(x) devuelve el índice más bajo donde aparece x
months = ['January', 'February', 'March']
prices = [238.11, 237.81, 238.91]
months.index('February')
1
print(prices[1])
237.81
min(list): devuelve el menor elemento
max(list): devuelve el mayor elemento
months = ['January', 'February', 'March']
prices = [238.11, 237.81, 238.91]
# Identify min price min_price = min(prices)# Identify min price index min_index = prices.index(min_price)# Identify the month with min price min_month = months[min_index] print(min_month)
February
Introducción a Python para finanzas