Lijsten in lijsten

Introductie tot Python voor Finance

Adina Howe

Instructor

Lijsten in lijsten

  • Lijsten kunnen verschillende datatypes bevatten, ook andere lijsten.

  • Voorbeeld: een geneste lijst met de maand en de bijbehorende consumentenprijsindex

      cpi = [['Jan', 'Feb', 'Mar'], [238.11, 237.81, 238.91]]
    
Introductie tot Python voor Finance

Subsetten van geneste lijsten

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]
Introductie tot Python voor Finance

Meer over subsetten van geneste lijsten

Hoe subset je een specifieke prijsindex?

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
Introductie tot Python voor Finance

Laten we oefenen!

Introductie tot Python voor Finance

Preparing Video For Download...