Skip to content

Instantly share code, notes, and snippets.

@khuyentran1401
Last active October 31, 2021 19:06
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save khuyentran1401/33aa3168830d1ae8a5e02cabbe5a9c77 to your computer and use it in GitHub Desktop.
def get_num_friends_map(data: pd.DataFrame):
"""Get a dictionary of people and their number of friends"""
all_people = list(set(data["person1"]).union(set(data["person2"])))
return {name: get_num_friends(friends, name) for name in all_people}
def get_num_friends_of_a_person_friends(
data: pd.DataFrame, person_id, num_friends_map: dict
):
friends = get_friends(data, person_id)
return [num_friends_map[friend_id] for friend_id in friends]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment