12.1 List access will not work?!?!


#1

I cannot figure this out. Either I made some really stupid mistake that I just missed or there might be a problem with codeacademy (Its usually the former but I cant find my mistake). So here is the code I am given:

once  = {'a': 1, 'b': 2}
twice = {'a': 2, 'b': 4}
for key in once:
    print "Once: %s" % once[key]
    print "Twice: %s" % twice[key]
    print key

It asks me to access the second value in the list. My first problem is this is a dictionary and not a list. Whenever I try print once[1] I get an error saying 1 is not a correct value. I can get the compiler to spit out "2" if I use print once["b"] but I still get "Oops, try again. Did you print the second element of the list? Remember, lists start indexing from 0." I have also tried printing the value in and out of the for loop but I get the same error.

Any help would be greatly appreciated. As I said I am sure I am just missing something stupid.


#2

Turns out it was a glitch. Switched computers and reset code which gave me the correct code of
n = [1, 3, 5]

God that was driving me nuts.


#3

For the exercise Printing out a list item by item in a function, the default code is:

n = [3, 5, 7]

for i in range(0, len(n)):
    print n[i]

Did you try pressing Reset Code button?