In exercise 39 of Learn Python the Hard Way (http://learnpythonthehardway.org/book/ex39.html), the following functions are defined (get_slot() and get()):
def get_slot(aMap, key, default=None):
"""
Returns the index, key, and value of a slot found in a bucket.
Returns -1, key, and default (None if not set) when not found.
"""
bucket = get_bucket(aMap, key)
for i, kv in enumerate(bucket):
k, v = kv
if key == k:
return i, k, v
return -1, key, default
def get(aMap, key, default=None):
"""Gets the value in a bucket for the given key, or the default."""
i, k, v = get_slot(aMap, key, default=default)
return v
Why write default=default when calling get_slot() ?
It would seem to me that simply calling get_slot() with 'default' would be sufficient? -> get_slot(aMap, key, default)
Is the default=default something to do with named vs positional function parameters? (as are discussed here: http://pythoncentral.io/fun-with-python-function-parameters/)
or is the default=default done for a different reason entirely?