nocasedict

A case-insensitive ordered dictionary for Python.

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.

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.

GitHub

https://github.com/pywbem/nocasedict