grantjenks / python-sortedcontainers

Python Sorted Container Types: Sorted List, Sorted Dict, and Sorted Set
http://www.grantjenks.com/docs/sortedcontainers/
Other
3.51k stars 203 forks source link

Add `get(key[, default])` method #197

Closed cjwcommuny closed 2 years ago

cjwcommuny commented 2 years ago

Add the get(key[, default]) method for sorted container like dict in Python.

Here is the doc copied from Python standard library:

get(key[, default])

Return the value for key if key is in the dictionary, else default. If default is not given, it defaults to None, so that this method never raises a [KeyError].

grantjenks commented 2 years ago

It’s there already.

cjwcommuny commented 2 years ago

SortedDict has already implemented get(key[, default]). But can we add this method to SortedSet?

grantjenks commented 2 years ago

Sets don’t typically work that way in Python.

Use inheritance to extend the data types as needed.