Using the old to build new

Yesterday in my intro to CS class, I introduced dictionaries.  My students started on some “simple” text-based game projects before the break and when I looked them over, I decided they could all use dictionaries even though that’s not something I had planned on teaching this year.  To explain dictionaries, I went back to lists.  The idea of both is that they serve as a place to store data and often, to pull data from.  Lists store all kinds of data, but there’s no way to associate the things in the list with each other.  For you non-CS people out there, a list looks like this:

[“apples”, “oranges”, “pears”] – a list of fruits

[1, 5, “thirty”, 25] – a list of numbers plus one number written as a string

A dictionary contains keys with associated values.  It looks like this:

{“apples”: 5, “oranges”: 2, “pears”: 3, “bananas”: 0} – a dictionary with keys as names of fruit and associated values, presumably the amount we have and yes, we have no bananas.

My students were writing games where they had questions (riddles or trivia) with associated answers.  I thought it a good idea to store those as a dictionary.  They had simply written out each question with a few following lines to check if the answer was right.

So, I reviewed lists, and especially iterating through a list, so that I could then show them how to iterate through a dictionary.  It was pretty interesting how difficult it was for them to remember how to iterate through a list.  You use a loop to repeat an action, which they’ve done before, but when they’d done it before, it was not in a context where you are using a loop to save time.  So, for example, we used a loop to repeat a series of movements on our robots.  Useful, but not the assembly-line kind of looping that one usually does with a list or dictionary.

I did find that once we went through that again, showing how to loop through a dictionary was pretty straightforward.  And though students had questions as they were implementing their dictionaries, they were less confused, I think, than they had been.  So I implemented a bit of my research-based teaching methods to review old material and connect it to new material.  And it seemed to work.  And, frankly, it was kind of fun.

Enhanced by Zemanta