3. In operator problem


#1



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


I expected it to work.

I don't understand why I get this error.

OUTPUT :

['Big', 'Coding', 'Spy']
['Datas', 'Is fun', 'Everyone']
('Big', 'Datas')
('Coding', 'Is fun')
('Spy', 'Everyone')
None

my_dict = {
    "Big": "Datas",
    "Spy": "Everyone",
    "Coding": "Is fun"
}

print(my_dict.keys())
print(my_dict.values())

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


#2

Typically, the parenthesis won't make a difference, but this IS python 2, so in this case, they're not working for you. For your print statements, just try:

print my_dict.keys()
print my_dict.values()

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

#3

oh they do make a difference, in python2 using parentheses like that means you get a tuple (an immutable list)

@betaninja08471, this is python2, don't use parentheses for print, that is for python3.

the exercise wants you to print key + value pair on separate lines, the , after [key] prevents this, remove it


#4

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