What should I do if I want to print key and value together? (2)


webster = {
"Aardvark" : "A star of a popular children's cartoon show.",
"Baa" : "The sound a goat makes.",
"Carpet": "Goes on the floor.",
"Dab": "A small amount."

Add your code below!

for key in webster :
print key and webster[key]


it only shows webster[key] results,
not key and value together.

Anyone knows?


try print webster.keys(key), webster.values(key)


Thanks for the reply.

I tried

print webster.keys(key), webster.values(key), which you told me

but it doesn't work.


yea tried it myself the two methods .items() and .values() dont take arguments.

Try print key, webster[key]


I tried..but doesn't work either..


Maybe to doing it inIDLE with a dictionary of your own, but for now just do what the instructions are telling you to do


@iamkwon: In order for you to print out the key-value pairs of a given dictionary, while using a loop instruction, you'll have to print the iterableVariable and the value at position iterate[iterableVariable]
Just like the example below:

for dictionaryEntry in myDictionary:
    print dictionaryEntry # your key value
    print myDictionary[dictionaryEntry] #the value at that key position


for key in webster:
print "%s %s" %(key+":",webster[key])