Skip to content

Commit f30b829

Browse files
Olyveneptunius
authored andcommitted
Fix broken lambda function
The lambda is broken because it cannot accept two parameters. Changing it to a single parameter to represent that tuple of key-value pairs fixes the issue. In the check, you also need to make sure to reference data in slot `0` to get the key.
1 parent 992a7da commit f30b829

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

source/hashtable.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def contains(self, key):
7777
index = self._bucket_index(key)
7878
bucket = self.buckets[index]
7979
# Check if an entry with the given key exists in that bucket
80-
entry = bucket.find(lambda (k, v): k == key)
80+
entry = bucket.find(lambda key_value: key_value[0] == key)
8181
return entry is not None # True or False
8282

8383
def get(self, key):
@@ -88,7 +88,7 @@ def get(self, key):
8888
index = self._bucket_index(key)
8989
bucket = self.buckets[index]
9090
# Find the entry with the given key in that bucket, if one exists
91-
entry = bucket.find(lambda (k, v): k == key)
91+
entry = bucket.find(lambda key_value: key_value[0] == key)
9292
if entry is not None: # Found
9393
# Return the given key's associated value
9494
assert isinstance(entry, tuple)
@@ -106,7 +106,7 @@ def set(self, key, value):
106106
bucket = self.buckets[index]
107107
# Find the entry with the given key in that bucket, if one exists
108108
# Check if an entry with the given key exists in that bucket
109-
entry = bucket.find(lambda (k, v): k == key)
109+
entry = bucket.find(lambda key_value: key_value[0] == key)
110110
if entry is not None: # Found
111111
# In this case, the given key's value is being updated
112112
# Remove the old key-value entry from the bucket first
@@ -126,7 +126,7 @@ def delete(self, key):
126126
index = self._bucket_index(key)
127127
bucket = self.buckets[index]
128128
# Find the entry with the given key in that bucket, if one exists
129-
entry = bucket.find(lambda (k, v): k == key)
129+
entry = bucket.find(lambda key_value: key_value[0] == key)
130130
if entry is not None: # Found
131131
# Remove the key-value entry from the bucket
132132
bucket.delete(entry)

0 commit comments

Comments
 (0)