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


#1

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]
`


#2

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

Anyone knows?


#3

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


#4

Thanks for the reply.

I tried

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

but it doesn't work.


#5

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

Try print key, webster[key]


#6

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


#7

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


#8

@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

#9

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