Python Forum
dot product of a list by a list in a dictionary stored as a value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dot product of a list by a list in a dictionary stored as a value
#1
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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dictionary in a list bashage 2 495 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 597 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Sort a list of dictionaries by the only dictionary key Calab 1 452 Oct-27-2023, 03:03 PM
Last Post: buran
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 1,091 Sep-24-2023, 05:03 AM
Last Post: deanhystad
Information Showing trendline formula in a table per product Carlossxx 0 629 May-03-2023, 08:34 AM
Last Post: Carlossxx
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  How to add list to dictionary? Kull_Khan 3 951 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  List all possibilities of a nested-list by flattened lists sparkt 1 878 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 1,717 Oct-26-2022, 04:03 PM
Last Post: deanhystad
Question Keyword to build list from list of objects? pfdjhfuys 3 1,500 Aug-06-2022, 11:39 PM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020