Python Forum

Full Version: dot product of a list by a list in a dictionary stored as a value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def similiar():
n=input()
for name,rating in ratingsdict.items():
if name == n:
return(rating)

for key in ratingsdict():
print(sum(ratingsdict[key]*rating for ratingsdict[key], rating in zip(ratingsdict[key], ratings)))

similiar()


I have created a dictionary already and I am trying to do the dot product on all of the lists within the dictionary with another list that is in rating but I am unable to achieve this.
Where is ratingsdict? Can similar() see the ratingsdict dictionary? Where is ratings? Can similar() see ratings? You need to surround your source with python tags to preserve the formatting. I don't know what code is part of similar() and what is not. If I don't know what code is in similar() I don't know if you are going to have a variable scope problem or not.

When I run this code I get an error that name ratingsdict is not defined. Is that the error you see? Do you see an error or do you just not get the results you expect? You need to provide more information about your problem and about what it is you are trying to do.