The 'in' Operator


#1



Oops, try again. It looks like you did not print out every key in my_dict.


Though there is just a small difference between the first and the second code, the first one is showing an error whereas the second one is passing. (However, both of them are giving the same output on the console)


my_dict = {
    "Name": "Guido",
    "Age": 56,
    "BDFL": True,
    "asdf": 52, 
    "asdfe": "asdf"
}
for d in my_dict:
    print "%s, %s"%(d,my_dict[d])

#The below code is working and no error msgs are generated

my_dict = {
    "Name": "Guido",
    "Age": 56,
    "BDFL": True,
    "asdf": 52, 
    "asdfe": "asdf"
}
for d in my_dict:
    print d,my_dict[d]


#2

You are looping for each key in my_dict. You need to then print out the key , then a space, then the value stored by that key. This is how you do it:

print key, my_dict[key]


#3

my_dict = { \
"1" : 1, \
"2" : 2, \
"3" : 3 \
}

for key in my_dict:
print key, my_dict[key],

can someone please explain why I am getting an error


#4

the error i'm getting is: "Oops, try again. It looks like you did not print out every key in my_dict"


#5

jkjk i got it fam adfasdfasdfa


#6

How did you solve that? I'm getting the same problem.


#7

Add "print" to the next line. It gets confused when it prints "None" right after the last term on the display thingy


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.