Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor bugfixes for dictionary.py #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions ex17_dictionary/dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,23 @@ def get_slot(self, key, default=None):

if bucket:
node = bucket.begin
i = 0

while node:
if key == node.value[0]:
return bucket, node
else:
node = node.next
i += 1

# fall through for both if and while above
return bucket, None
return bucket, default

def get(self, key, default=None):
"""Gets the value in a bucket for the given key, or the default."""
bucket, node = self.get_slot(key, default=default)
return node and node.value[1] or node
try:
return node and node.value[1] or node
except AttributeError:
return node

def set(self, key, value):
"""Sets the key to the value, replacing any existing value."""
Expand Down