That Blue Square Thing

AQA Computer Science GCSE

Programming projects - File Handling

Working with Lists

Lists can be extremely powerful tools to use in a programming project. It might be that you use simple lists to hold data, have to read in or write a list of data or use 2D arrays (lists of lists) to manipulate data.

Don't forget that a Python list is an array. An exam will always refer to them as arrays.

The reading lists page deals with how to read a list of lists from a text file and store it in an array.

Basic Strategy for Working Through a List

Using lists require a methodical approach. The pseudocode below shows one way to do that (don't forget that lists are called arrays in pseudocode).

FOR aLine in anArray
nextItem <- aLine # take the next item and store it
# do whatever needs doing

ENDFOR

One way that this technique could be implemented in Python is:

for aLine in aList:
nextItem = aLine
# do whatever needs doing

There are, of course, a whole range of things you might do to the items in the array.

Some lists to work with

Here are three more lists that you could use to work on. The last two are lists of lists - so they're two-dimensional arrays. Which makes them a little harder to use.

Text file iconComedy dogs - just the names of comedy dogs

Text file iconSongs text file - the two letter code is a genre field

Text file iconCountry data - the number is the population in millions