I am trying to create a dictionary with two keys, but I get a KeyError when assigning elements. I do not get an error when using each of the keys separately, and the syntax seems pretty simple, so I'm at a dead end.
searchIndices = ['Books', 'DVD']
allProducts = {}
for index in searchIndices:
res = amazon.ItemSearch(Keywords = entity, SearchIndex = index, ResponseGroup = 'Large', ItemPage = 1, Sort = "salesrank", Version = '2010-11-01')
products = feedparser.parse(res)
for x in range(10):
allProducts[index][x] = { 'price' : products['entries'][x]['formattedprice'],
'url' : products['entries'][x]['detailpageurl'],
'title' : products['entries'][x]['title'],
'img' : products['entries'][x]['href'],
'rank' : products['entries'][x]['salesrank']
}
I do not believe that the problem is with feedparser (which converts xml to dict) or with the results that I get with amazon, since I have no problem creating a dict when using 'allProducts [x]' or 'allProducts [index]' but not both.
What am I missing?
source
share