Title: Lesson 5: Data structures
Course: Basic scripting and programming > Section: Course Content

Take a look at Python's built-in data types and see what these can be used for. Furthermore, we will take a look at input/output through files.

Objectives:

Getting familiar with Python's intrinsic data types:

- strings
- lists and tuples
- dictionaries
- files

Entrance requirements:

- Lessons 1-4

Required materials:

- Computer with Python
- The course book “Think Python”, chapters 8, 10, 11, 12 and 14

Learning outcomes:

At the end of the lesson the student:

- knows about strings, sequences, slices, methods and the in operator
- knows about lists and list operations, slices, methods
- is aware that lists can be used as arguments to functions
- knows about dictionaries and keys and values of dictionaries
- knows how to loop over dictionaries
- knows how other data types can be used as values in dictionaries
- knows what the limitations are for dictionary keys
- knows about the data type called tuple
- knows the similarities and differences between lists and tuples
- knows how a dictionary can be turned into a list of tuples
- knows that tuples can be compared
- knows about the file data type and the open function
- knows how files on disk can be written and read in Python
- knows about filenames and paths
- knows about exceptions and the try-statement and except-clause
- is able to apply all of the above

Learning activities:

- Read chapters 8, 10, 11, 12 and 14 of the course book “Think Python”
However, you may lightly skim through sections 14.6, 14.7 and 14.8.

- As an extra challenge you can do chapters 9 and 13 as well!

Tasks:

Make the following exercises:

- Exercises 8.1, 8.2, 8.5
- Exercises 10.2, 10.3, 10.4, 10.6
- Exercises 11.1
- Using the function on page 109, what is the largest Fibonacci number that can be calculated now? Compare this to your answer in lesson 4!
known = {0:0, 1:1}
def fibonacci(n):
if not n in known:
           known[n] = fibonacci(n-1) + fibonacci(n-2)
return known[n]
SUBMIT all your answers in a PDF document!
Planned time frame for this lesson:
6 hours