Some list exercises
- Create a variable l1 which is pointing to a list with the five elements 1,2,3,4,5.
For the following, try to write solutions which are as general as possible. That is, try to find solutions that would also work if you didn't know how long the list was or what the elements of the list were.
- Write an expression that retrieves the 3rd element from the list (i.e.3).
- Write an expression that retrieves the sublist containing the third element up to the last element (i.e. [3,4,5]).
- Write an expression that retrieves the last element. Try to write it such that it would also work if you didn't know how long the list was.
- Write a statement that makes the first element in the list 100.
- Write a statement that adds the elements 200, 300, 400 to the end of the list.
- Write a statement that inserts the elements 1000, 2000 between the 2nd and 3rd element.