From f099a0ad3f3e6ac16727bc29e77d1e3ac8d40e22 Mon Sep 17 00:00:00 2001 From: cclauss Date: Wed, 7 Mar 2018 01:37:46 +0100 Subject: [PATCH] Convert all .py files to be valid Python (#98) --- .../call_center/call_center.py | 11 ++-- .../deck_of_cards/deck_of_cards.py | 5 +- .../lru_cache/lru_cache.py | 17 ++++--- .../online_chat/online_chat.py | 51 ++++++++++++++----- .../parking_lot/parking_lot.py | 12 +++-- .../social_graph/social_graph_snippets.py | 1 + .../web_crawler/web_crawler_snippets.py | 20 ++++---- 7 files changed, 78 insertions(+), 39 deletions(-) diff --git a/solutions/object_oriented_design/call_center/call_center.py b/solutions/object_oriented_design/call_center/call_center.py index 7bdd992b386..a2785594478 100644 --- a/solutions/object_oriented_design/call_center/call_center.py +++ b/solutions/object_oriented_design/call_center/call_center.py @@ -112,6 +112,11 @@ def _dispatch_call(self, call, employees): return employee return None - def notify_call_escalated(self, call): # ... - def notify_call_completed(self, call): # ... - def dispatch_queued_call_to_newly_freed_employee(self, call, employee): # ... \ No newline at end of file + def notify_call_escalated(self, call): + pass + + def notify_call_completed(self, call): + pass + + def dispatch_queued_call_to_newly_freed_employee(self, call, employee): + pass diff --git a/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py b/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py index 2ec4f1bc90b..8dc565483ea 100644 --- a/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py +++ b/solutions/object_oriented_design/deck_of_cards/deck_of_cards.py @@ -92,7 +92,7 @@ def score(self): def possible_scores(self): """Return a list of possible scores, taking Aces into account.""" - # ... + pass class Deck(object): @@ -113,4 +113,5 @@ def deal_card(): return None return card - def shuffle(self): # ... \ No newline at end of file + def shuffle(self): + pass diff --git a/solutions/object_oriented_design/lru_cache/lru_cache.py b/solutions/object_oriented_design/lru_cache/lru_cache.py index 3652aeb6127..c2c38faa41f 100644 --- a/solutions/object_oriented_design/lru_cache/lru_cache.py +++ b/solutions/object_oriented_design/lru_cache/lru_cache.py @@ -11,9 +11,14 @@ def __init__(self): self.head = None self.tail = None - def move_to_front(self, node): # ... - def append_to_front(self, node): # ... - def remove_from_tail(self): # ... + def move_to_front(self, node): + pass + + def append_to_front(self, node): + pass + + def remove_from_tail(self): + pass class Cache(object): @@ -26,7 +31,7 @@ def __init__(self, MAX_SIZE): def get(self, query) """Get the stored query result from the cache. - + Accessing a node updates its position to the front of the LRU list. """ node = self.lookup[query] @@ -37,7 +42,7 @@ def get(self, query) def set(self, results, query): """Set the result for the given query key in the cache. - + When updating an entry, updates its position to the front of the LRU list. If the entry is new and the cache is at capacity, removes the oldest entry before the new entry is added. @@ -58,4 +63,4 @@ def set(self, results, query): # Add the new key and value new_node = Node(results) self.linked_list.append_to_front(new_node) - self.lookup[query] = new_node \ No newline at end of file + self.lookup[query] = new_node diff --git a/solutions/object_oriented_design/online_chat/online_chat.py b/solutions/object_oriented_design/online_chat/online_chat.py index d74262953da..c9e5a984ad5 100644 --- a/solutions/object_oriented_design/online_chat/online_chat.py +++ b/solutions/object_oriented_design/online_chat/online_chat.py @@ -6,11 +6,20 @@ class UserService(object): def __init__(self): self.users_by_id = {} # key: user id, value: User - def add_user(self, user_id, name, pass_hash): # ... - def remove_user(self, user_id): # ... - def add_friend_request(self, from_user_id, to_user_id): # ... - def approve_friend_request(self, from_user_id, to_user_id): # ... - def reject_friend_request(self, from_user_id, to_user_id): # ... + def add_user(self, user_id, name, pass_hash): + pass + + def remove_user(self, user_id): + pass + + def add_friend_request(self, from_user_id, to_user_id): + pass + + def approve_friend_request(self, from_user_id, to_user_id): + pass + + def reject_friend_request(self, from_user_id, to_user_id): + pass class User(object): @@ -25,12 +34,23 @@ def __init__(self, user_id, name, pass_hash): self.received_friend_requests_by_friend_id = {} # key: friend id, value: AddRequest self.sent_friend_requests_by_friend_id = {} # key: friend id, value: AddRequest - def message_user(self, friend_id, message): # ... - def message_group(self, group_id, message): # ... - def send_friend_request(self, friend_id): # ... - def receive_friend_request(self, friend_id): # ... - def approve_friend_request(self, friend_id): # ... - def reject_friend_request(self, friend_id): # ... + def message_user(self, friend_id, message): + pass + + def message_group(self, group_id, message): + pass + + def send_friend_request(self, friend_id): + pass + + def receive_friend_request(self, friend_id): + pass + + def approve_friend_request(self, friend_id): + pass + + def reject_friend_request(self, friend_id): + pass class Chat(metaclass=ABCMeta): @@ -51,8 +71,11 @@ def __init__(self, first_user, second_user): class GroupChat(Chat): - def add_user(self, user): # ... - def remove_user(self, user): # ... + def add_user(self, user): + pass + + def remove_user(self, user): + pass class Message(object): @@ -77,4 +100,4 @@ class RequestStatus(Enum): UNREAD = 0 READ = 1 ACCEPTED = 2 - REJECTED = 3 \ No newline at end of file + REJECTED = 3 diff --git a/solutions/object_oriented_design/parking_lot/parking_lot.py b/solutions/object_oriented_design/parking_lot/parking_lot.py index c34c010b6e8..9167d9fdb76 100644 --- a/solutions/object_oriented_design/parking_lot/parking_lot.py +++ b/solutions/object_oriented_design/parking_lot/parking_lot.py @@ -1,4 +1,5 @@ from abc import ABCMeta, abstractmethod +from enum import Enum class VehicleSize(Enum): @@ -92,11 +93,11 @@ def park_vehicle(self, vehicle): def _find_available_spot(self, vehicle): """Find an available spot where vehicle can fit, or return None""" - # ... + pass def _park_starting_at_spot(self, spot, vehicle): """Occupy starting at spot.spot_number to vehicle.spot_size.""" - # ... + pass class ParkingSpot(object): @@ -117,5 +118,8 @@ def can_fit_vehicle(self, vehicle): return False return vehicle.can_fit_in_spot(self) - def park_vehicle(self, vehicle): # ... - def remove_vehicle(self): # ... \ No newline at end of file + def park_vehicle(self, vehicle): + pass + + def remove_vehicle(self): + pass diff --git a/solutions/system_design/social_graph/social_graph_snippets.py b/solutions/system_design/social_graph/social_graph_snippets.py index 32941111c20..f1cc6963803 100644 --- a/solutions/system_design/social_graph/social_graph_snippets.py +++ b/solutions/system_design/social_graph/social_graph_snippets.py @@ -61,3 +61,4 @@ def __init__(self, person_ids, lookup): def bfs(self, source, dest): # Use self.visited_ids to track visited nodes # Use self.lookup to translate a person_id to a Person + pass diff --git a/solutions/system_design/web_crawler/web_crawler_snippets.py b/solutions/system_design/web_crawler/web_crawler_snippets.py index e85e23610cb..99d5a37875e 100644 --- a/solutions/system_design/web_crawler/web_crawler_snippets.py +++ b/solutions/system_design/web_crawler/web_crawler_snippets.py @@ -2,33 +2,33 @@ class PagesDataStore(object): - def __init__(self, db); + def __init__(self, db): self.db = db - ... + pass def add_link_to_crawl(self, url): """Add the given link to `links_to_crawl`.""" - ... + pass def remove_link_to_crawl(self, url): """Remove the given link from `links_to_crawl`.""" - ... + pass - def reduce_priority_link_to_crawl(self, url) + def reduce_priority_link_to_crawl(self, url): """Reduce the priority of a link in `links_to_crawl` to avoid cycles.""" - ... + pass def extract_max_priority_page(self): """Return the highest priority link in `links_to_crawl`.""" - ... + pass def insert_crawled_link(self, url, signature): """Add the given link to `crawled_links`.""" - ... + pass def crawled_similar(self, signature): """Determine if we've already crawled a page matching the given signature""" - ... + pass class Page(object): @@ -41,7 +41,7 @@ def __init__(self, url, contents, child_urls): def create_signature(self): # Create signature based on url and contents - ... + pass class Crawler(object):