For one of the functions of my assignment I am supposed to write a code for this recommendation score below.
But I have no idea where I should start off. I was told to use helper functions but I dont know what kinda helper functions, like for instance their name
Recommendation score
For each person, all people in the social network who they are not currently friends with are potential friends. For a particular person, each potential friend is scored using the following point system:
- for every mutual friend that the person and the potential friend have, add 1 point to the potential friend's score
- for each network that the person and the potential friend both belong to, add 1 point to the potential friend's score
- if the person has the same last name as a potential friend who was identified through one or both of the previous two methods, add 1 point to the potential friend's score
The link to the assignment is at http://bit.ly/H9hCia, if it makes it easier, its just based on this how would I start it. I was told by everyone that as long as I understand this description then I can start on it.But that doesn't seem like it, when you guys read it do u need more information? Because Im so confused so I decided to post here and ask what you guys think. Since I can't start on it at all. If I do need to further explain more I will.
dictionary
, and playing around with the data, trying do things with your string
when you are comfortable doing that, you can start thinking about what the project want, and how to do them. I hope this help - George 2012-04-04 22:10
A few hints.
You have a social graph. The 'person to friends' dict is its incidence table: for each node (person) it shows which nodes it connects to.
"Mutual friends" is obviously two persons that have each other in their incidence lists. Make a helper function that determines if two given people are mutual friends. Maybe make a function that lists all mutual friends of a given person.
Then you can enumerate persons in 'persons to friends' (dict.keys()
is your friend) and compute scores. Be sure to check that you don't include actual friends of a person into potential friends.
To find whether two persons belong to at least one common network, convert lists of networks into sets and use set intersection (&
).
To find first and last names, use str.split() on them.
Start an interactive Python interpreter. Write simple functions, play with your data a bit. Don't try to fit everything in your head at once and write down in one go. Instead, experiment.
Before you start thinking about writing functions and all. You should tell us what do you know or what do you not know. Do you know what is a dictionary? Your project require dictionary
, do you know how to create variables? As a student myself, I suggestion you start by writing the code itself first, playing around with the data, (such as loading them, printing them, comparing them). Doing so you will be more comfortable with writing code.
First thing you should do is to learn dictionary
, figure out how to create one, how to set the value, get the values, etc. Read the following tutorial, and see if you understand dictionary. It is no point to try to write a function, if you don't know how to use the dictionary
to being with.
Read this for dictionary
: http://docs.python.org/library/stdtypes.html#typesmapping
Read this for string
: http://docs.python.org/tutorial/introduction.html#strings
Read this for for
, if
and others: http://docs.python.org/tutorial/controlflow.html
When you finish the that three tutorials, you will learn how to create and use dictionary
, and string
. Then you can think about how to put your codes into function, and how to write your program to solve the problem. We want to help, but we need to know where you get stuck, give us information such as the error message, or (how to do xxx) (try google it first). Good luck.
function
here: http://www.tutorialspoint.com/python/python_functions.htm And you are welcome to post question if you are stuc - George 2012-04-05 03:46