Skip to content
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
13 changes: 13 additions & 0 deletions semidbm/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ def keys(self):

def values(self):
return [self[key] for key in self._index]

def set_default(self, key, default_value):
"""
If the key already exists in the items dictionary, the value
will be returned in the dictionary; else the value will be added
to the dictionary and the default_value will be returned.
"""

if key in self:
return self[key]

self[key] = default_value
return default_value

def close(self, compact=False):
"""Close the db.
Expand Down