This weeks entry is rather short as life took priority.

So this, the last week (week 7), of Learn to Program at the University of Toronto went over dictionaries and tuples. A giant step away of describing a dictionary in my mind is "a list using curly brackets". Yet, they really aren't. They're more. Much more.

Having to try and work them out, to understand them, I try to associate them with other things I'm familiar with. So then, dictionaries are not ordered, like lists are. They come with a pair of values, meaning they contain a pair of data in the 'key': 'value' type. While dictionary keys are immutable, the values are not (I think). You can delete a key:value pair kind of like how you remove an item in a list.


But what does this mean? To me, not much. At least not yet. I mean, with all of the square brackets, parenthesis, and curly brackets being used all at the same time its easy to become confused. I hope in time they'll become familiar.


We went over things such as opening, inverting, and creating a dictionary. This can be done in a few ways such as reading a file and importing that data into a dictionary.

file = open('/home/user/text_filename_here.txt')

Or by just creating one by hand as such:

fruit_color = {
    'banana': 'yellow',
    'cherry': 'red',
    'orange': 'orange',
    'pear': 'green',
    'peach': 'orange',
    'plug': 'purple',
    'pomegranate': 'red',
    'strawberry': 'red'}

I've come to a basic understanding on how to access a value from a dictionary. But this is where I get really slow. You create a dictionary using curly brackets {}, but you call on a value by using the square brackets []. So if I wanted to find the color of pear I would: fruit_color['pear'] and then 'green' would be returned. I'm sure it takes a lot of getting used to. Writing it out as I go helps me out. Mostly it gets the ball rolling for my brain and then after a bit I can just follow along in my head.


I'm wanting to do more about understanding programming, computer science, first then I am wanting to jump into a specific language. I feel that knowing the logic and flow of something first will make it easier for me in the long run. I hope to find out sooner than later, but thats my plan for now.


Tuples are kind of like lists. Sort of.
Lists are mutable sequences. Lists use square brackets [].
Tuples are immutable sequences. Tuples use parenthesis ().
And like lists, you can index tuples and even iterate over them. I haven't went into tuples much just yet. So this was more of a get your toes wet lesson.

And is it pronounced 'TWO'ples or 'TUP'les ?