Aren't these two blocks of code functionally identical?


Maybe this isn’t in the right forum, but I’m currently on the supermarket lesson in which you have to iterate through two dictionaries with a for loop and follow a specific output format. This was my answer to the prompt:

prices = {
  "banana" : 4,
  "apple" : 2,
  "orange" : 1.5,
  "pear" : 3

stock = {
  "banana" : 6,
  "apple" : 0,
  "orange" : 32,
  "pear" : 15  

for items in prices:
  print items 
  print """price: %s
stock: %s""" % (prices[items], stock[items])
  print ""

And this is the “solution:”

prices = {"banana": 4,"apple": 2,"orange": 1.5,"pear": 3}

stock = {"banana": 6, "apple": 0, "orange": 32, "pear": 15}

for food in prices:
  print food
  print "price: %s" % prices[food]
  print "stock: %s" % stock[food]

I’m pretty sure these output exactly the same thing (except for the extra print statement intended to separate items) yet it wouldn’t let me complete the lesson. Is there anything I did wrong here?

edit: I did actually check whether these two had identical output and as far as I can see, they do.

edit 2: actually scratch that; it seems like the extra space between iterations is the issue, but then again it was probably my interpretation of the prompt that screwed me up. The way the prompt presented the code made it seem like there was supposed to be space between iterations.

edit 3: Huh. It seems like it might be the concatenation. Apparently the system doesn’t like that.