Sunday, 25 January 2015

The trouble I met when I did the lab1 of CSC148

The problem was not very difficult, but it still took me a little time to deal with. In lab1 work, we needed to collect the information about race members. So I decide to choose dictionary, whose keys are time intervals and values are members' names. However, when I added a new name to the key, it caused a error. I had tried many ways to solve this error but all of them did not work. So, I asked help from classmates and TA and I still got the same result.

After thinking for a while, I was awared that I could not use method APPEND for a number or string, which caused the error. What I need do is let the value of dictionary be a list of strings. Like 'mike' -> ['mike']. So, I can append a new name to the existing value.

From this one, I need pay more attention to the type of value of dictionary when I use some methods.

1 comment:

  1. Hi there,

    It' great that you finally figured out a solution to this problem :) You have an interesting approach, I would say. In the last exercise of the lab handout, a bunch of names are given and some of the names repeat, which suggests that we must update the time intervals for that individual. My TA caught this when he looked at my code, and I had to reorganize my code to solve this issue. I used dictionaries, of course, but it looks something like this:

    {'Tom': 'under 20 minutes'}

    ....so if Tom appears again, I could easily update his interval time.

    I would definitely like to hear how you solved this exercise!

    ReplyDelete