Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:53:18+00:00 2026-05-26T00:53:18+00:00

I am trying to set up a function that will calculate a score for

  • 0

I am trying to set up a function that will calculate a score for the similarity of two films. There are pre-existing dictionaries that with the films as keys and either the directors, genres, or main actors are values. There are three actor dictionaries (the 3 lead actors for each film is listed). The code mostly works fine but sometimes I get a resulting score greater than what I should get.

# create a two-variable function to deterime the FavActor Similarity score: 
def FavActorFunction(film1,film2):

    #set the result of the FavActor formula between two films to a default of 0.
    FavActorScore = 0
    #add 3 to the similarity score if the films have the same director.
    if direct[film1] == direct[film2]:
        FavActorScore += 3
    #add 2 to the similarity score if the films are in the same genre.
    if genre[film1] == genre[film2]:
        FavActorScore += 2
    #add 5 to the similarity score for each actor they have in common.
    if actor1[film1] == actor1[film2] or actor2[film2] or actor3[film2]:
        FavActorScore += 5
    if actor2[film1] == actor1[film2] or actor2[film2] or actor3[film2]:
        FavActorScore += 5     
    if actor3[film1] == actor1[film2] or actor2[film2] or actor3[film2]:
        FavActorScore += 5
    #print the resulting score.                    
    return FavActorScore

my assumption is that in counting the actors that they have in common, it is counting some things twice. is there a way to revise this part of the code so it comes out with a more accurate result?

if actor1[film1] == actor1[film2] or actor2[film2] or actor3[film2]:   
    FavActorScore += 5
if actor2[film1] == actor1[film2] or actor2[film2] or actor3[film2]:  
    FavActorScore += 5     
if actor3[film1] == actor1[film2] or actor2[film2] or actor3[film2]:  
    FavActorScore += 5     
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:53:19+00:00Added an answer on May 26, 2026 at 12:53 am

    Try with the in condition :

    if actor1[film1] in (actor1[film2], actor2[film2], actor3[film2]):
       FavActorScore += 5 
    if actor2[film1] in ( actor1[film2], actor2[film2], actor3[film2]):
       FavActorScore += 5
    if actor3[film1] in (actor1[film2], actor2[film2], actor3[film2]):
       FavActorScore += 5
    

    When you write a==b or c or d this is true if a is equal to b or if c is true or if d is true not true if a is equal to b or c or d.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to set up an email function that will email the last
I'm trying to make a function template that will accept two (or more) of
I am trying to set the compilation-error-regexp-alist in a function that I add as
is it Possible to create a function that will create a set with an
I am trying to make a function in PHP that will allow me to
I'm trying to write a regex function that will identify and replace a single
I'm trying to write a function that will get me the attribute of a
I'm trying to set up a test that will tell me whether a variable
I am trying to set up a global variable that will be read across
I'm trying to create a set of function templates that can take different types

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.