A case-insensitive ordered dictionary for Python
Project description
Overview
Class NocaseDict is a case-insensitive ordered dictionary that preserves the original lexical case of its keys.
Example:
$ python
>>> from nocasedict import NocaseDict
>>> dict1 = NocaseDict({'Alpha': 1, 'Beta': 2})
>>> dict1['ALPHA'] # Lookup by key is case-insensitive
1
>>> print(dict1) # Keys are returned with the original lexical case
NocaseDict({'Alpha': 1, 'Beta': 2})
The NocaseDict class supports the functionality of the built-in dict class of Python 3.8 on all Python versions it supports with the following exceptions (and the case-insensitivity of course):
The iter..(), view..() and has_key() methods are only present on Python 2, consistent with the built-in dict class.
The keys(), values() and items() methods return a list on Python 2 and a dictionary view on Python 3, consistent with the built-in dict class.
The case-insensitivity is achieved by matching any key values as their casefolded values. By default, the casefolding is performed with str.casefold() on Python 3 and with str.lower() on Python 2. The default casefolding can be overridden with a user-defined casefold method.
Functionality can be added using mixin classes:
HashableMixin mixin class: Adds case-insensitive hashability.
KeyableByMixin mixin generator function: Adds ability to get the key from an attribute of the value object.
Why yet another case-insensitive dictionary: We found that all previously existing case-insensitive dictionary packages on Pypi either had flaws, were not well maintained, or did not support the Python versions we needed.
Installation
To install the latest released version of the nocasedict package into your active Python environment:
$ pip install nocasedict
This will also install any prerequisite Python packages.
For more details and alternative ways to install, see Installation.
Documentation
Change History
Contributing
For information on how to contribute to the nocasedict project, see Contributing.
License
The nocasedict project is provided under the GNU Lesser General Public License (LGPL) version 2.1, or (at your option) any later version.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nocasedict-1.1.0.tar.gz
.
File metadata
- Download URL: nocasedict-1.1.0.tar.gz
- Upload date:
- Size: 41.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac551de692be6aea5b43ac3f2c33780df940013ac6dd0718fb552c8b560ba661 |
|
MD5 | 6055807366956542c0cdb91aa2f711b8 |
|
BLAKE2b-256 | e2a7cbbda960e7adac9eeceed1ad8ab6ace018a8a700c216cccbbc2c94e7bbe7 |
File details
Details for the file nocasedict-1.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: nocasedict-1.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 23.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1008b548315d5c95e3e75b9955ad80b9d02432eab867f9257f1983962fcc2af1 |
|
MD5 | d6d9801be909066c5801d70a0bdab1ac |
|
BLAKE2b-256 | f69e5af9688b0eab38d4ddcec614ef972f28d1c62926ed758415d0d104a9ee6f |