Skip to content

Commit

Permalink
snake case
Browse files Browse the repository at this point in the history
  • Loading branch information
br80 committed Nov 9, 2019
1 parent 7cbe577 commit c2ed527
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions projects/social/social.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ def __init__(self, name):

class SocialGraph:
def __init__(self):
self.lastID = 0
self.last_id = 0
self.users = {}
self.friendships = {}

def addFriendship(self, userID, friendID):
def add_friendship(self, user_id, friend_id):
"""
Creates a bi-directional friendship
"""
if userID == friendID:
if user_id == friend_id:
print("WARNING: You cannot be friends with yourself")
elif friendID in self.friendships[userID] or userID in self.friendships[friendID]:
elif friend_id in self.friendships[user_id] or user_id in self.friendships[friend_id]:
print("WARNING: Friendship already exists")
else:
self.friendships[userID].add(friendID)
self.friendships[friendID].add(userID)
self.friendships[user_id].add(friend_id)
self.friendships[friend_id].add(user_id)

def addUser(self, name):
def add_user(self, name):
"""
Create a new user with a sequential integer ID
"""
self.lastID += 1 # automatically increment the ID to assign the new user
self.users[self.lastID] = User(name)
self.friendships[self.lastID] = set()
self.last_id += 1 # automatically increment the ID to assign the new user
self.users[self.last_id] = User(name)
self.friendships[self.last_id] = set()

def populateGraph(self, numUsers, avgFriendships):
def populate_graph(self, numUsers, avgFriendships):
"""
Takes a number of users and an average number of friendships
as arguments
Expand All @@ -41,7 +41,7 @@ def populateGraph(self, numUsers, avgFriendships):
The number of users must be greater than the average number of friendships.
"""
# Reset graph
self.lastID = 0
self.last_id = 0
self.users = {}
self.friendships = {}
# !!!! IMPLEMENT ME
Expand All @@ -50,9 +50,9 @@ def populateGraph(self, numUsers, avgFriendships):

# Create friendships

def getAllSocialPaths(self, userID):
def get_all_social_paths(self, user_id):
"""
Takes a user's userID as an argument
Takes a user's user_id as an argument
Returns a dictionary containing every user in that user's
extended network with the shortest friendship path between them.
Expand All @@ -66,7 +66,7 @@ def getAllSocialPaths(self, userID):

if __name__ == '__main__':
sg = SocialGraph()
sg.populateGraph(10, 2)
sg.populate_graph(10, 2)
print(sg.friendships)
connections = sg.getAllSocialPaths(1)
connections = sg.get_all_social_paths(1)
print(connections)

0 comments on commit c2ed527

Please sign in to comment.