Typed and Tested Case Insensitive Dictionary which was inspired by Raymond Hettinger
Project description
caseless-dictionary
A simple, fast, typed, and tested implementation for a python3.6+ case-insensitive dictionary. This class extends and maintains the original functionality of the builtin dict
.
Key Features:
- Easy: If you don't care about the case of the key in a dictionary then this implementation is easy to use since it acts just like a
dict
obj. - Great Developer Experience: Being fully typed makes it great for editor support.
- Fully Tested: Our test suit fully tests the functionality to ensure that
CaselessDict
runs as expected. - There is More!!!:
- ModifiableItemsDict: CaselessDict is built on top of the
ModifiableItemsDict
, which is a library that enables the user to modify the key or/and value ofdict
type object at runtime.
- ModifiableItemsDict: CaselessDict is built on top of the
Installation
pip install caseless-dictionary
Simple CaselessDict Example
from caseless_dictionary import CaselessDict
normal_dict: dict = {" CamelCase ": 1, " UPPER ": "TWO", 3: " Number as Key "}
caseless_dict: CaselessDict = CaselessDict(normal_dict)
print(caseless_dict) # {'camelcase': 1, 'upper': 'TWO', 3: 'Number as Key'}
print("CamelCase" in caseless_dict) # True
print("camelcase" in caseless_dict) # True
print(caseless_dict[" camelCASE "]) # 1
Simple UpperCaselessDict Example
from caseless_dictionary import UpperCaselessDict
from typing import Iterable
iterable: Iterable = [(" wArNIng", 0), ("deBug ", 10)]
upper_caseless_dict: dict = UpperCaselessDict(iterable)
print(upper_caseless_dict) # {'WARNING': 0, 'DEBUG': 10}
print("warning"in upper_caseless_dict) # True
upper_caseless_dict["WarninG"] = 30
print(upper_caseless_dict) # {'WARNING': 30, 'DEBUG': 10}
Simple TitleCaselessDict Example
from caseless_dictionary import TitleCaselessDict
from typing import Iterable
iterable: Iterable = {" Brave ": 1, " ProtonMail ": 2}
title_caseless_dict: dict = TitleCaselessDict(iterable)
print(title_caseless_dict) # {'Brave': 1, 'Protonmail': 2}
title_caseless_dict.pop(" protonMAIL ")
print(title_caseless_dict) # {'Brave': 1}
Acknowledgments
During the class '(Advanced) Python For Engineers III' taught by Raymond Hettinger, Raymond taught us how to inherit from the builtin Python dict
by creating a Case-insensitive Dict.
I thought this was a wonderful learning experience so I decided to create a project that would build upon what he taught.
Project details
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
Close
Hashes for caseless-dictionary-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb2b4159ffae9e8f987e9fc66e46398abbc459cc607e82d04ebcd664f6b45a96 |
|
MD5 | 43ecceef3c2b307b91339e4b66b62449 |
|
BLAKE2b-256 | b470737d99d4daf5635efdd7578bf91dafad6c96d39a55286a214f32cd26e667 |
Close
Hashes for caseless_dictionary-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d634ffd47e601d609c50d0d323b8f499529a5986bbdaa2fe335b7762691317b |
|
MD5 | 6d2baa8ff0394a21766c3c8234061675 |
|
BLAKE2b-256 | 6f4e3f042168e72820a250e682a0b480f1a046fdc9a0b0bba3ba45fab84d6c14 |