-2

My code: text = [['Name', 'Surname', '2009']]

What I tried to do: text[1];

I want so that the 'Surname' would print out, but I keep getting - IndexError: list index out of range.

2
  • 1
    You have a list of list. text[0][1] would be 'Surname'.
    – jonrsharpe
    Mar 27, 2020 at 14:23
  • This is a list within a list. so text[0] will give you the inner list then you need [1] to acces sindex 1 of the inner list. So text[0][1] says access the list in index 0 or text then access surname in index 1 of the inner list Mar 27, 2020 at 14:26

1 Answer 1

1

This is a nested list.

text = [['Name', 'Surname', '2009']]

text[0] = ['Name', 'Surname', '2009']

text[0][1] = 'Surname'
2
  • thanks, can you also help me how can I sort the date with sort() if let's say, there is 2014, 2005 and 2009?
    – lucutes
    Mar 27, 2020 at 14:45
  • Use dates.sort() to sort in ascending order.
    – Viswa
    Mar 27, 2020 at 15:23

Not the answer you're looking for? Browse other questions tagged or ask your own question.