Introduction to Python for Finance
Adina Howe
Instructor
prices.sort()
type(prices)
list.method()
list.sort()
sorts list elements in ascending order
prices = [238.11, 237.81, 238.91]
prices.sort()
print(prices)
[237.81, 238.11, 238.91]
list.append()
adds a single element to a list
months = ['January', 'February', 'March']
months.append('April')
print(months)
['January', 'February', 'March', 'April']
list.extend()
adds each element to a list
months.extend(['May', 'June', 'July'])
print(months)
['January', 'February', 'March', 'April', 'May', 'June', 'July']
list.index(x)
returns the lowest index where the element x appears
months = ['January', 'February', 'March']
prices = [238.11, 237.81, 238.91]
months.index('February')
1
print(prices[1])
237.81
min(list)
: returns the smallest element
max(list)
: returns the largest element
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
Introduction to Python for Finance