Introduction to Python for Finance
Adina Howe
Instructor
Lists can contain various data types, including lists themselves.
Example: a nested list describing the month and its associated consumer price index
cpi = [['Jan', 'Feb', 'Mar'], [238.11, 237.81, 238.91]]
months = ['Jan', 'Feb', 'Mar']
print(months[1])
'Feb'
cpi = [['Jan', 'Feb', 'Mar'], [238.11, 237.81, 238.91]]
print(cpi[1])
[238.11, 237.81, 238.91]
How would one subset out a specific price index?
cpi = [['Jan', 'Feb', 'Mar'], [238.11, 237.81, 238.91]]
print(cpi[1])
[238.11, 237.81, 238.91]
print(cpi[1][0])
238.11
Introduction to Python for Finance