Reference library

Dictionaries & sets

Key–value maps, uniqueness, counting, grouping, and fast lookups.

1 match
Dictionaries & sets medium

Build a Case-Insensitive Dict with a Wrapper Class in Python

Create a custom dict subclass that treats keys as case-insensitive by normalizing them to lowercase, with a full set of common dict methods.

dictionary case-insensitive wrapper
Python
class CaseInsensitiveDict:
    def __init__(self, data=None):
        self._data = {}
        if data:
            self.update(data)

    def __setitem__(self, key, value):
        self._data[str(key).lower()] = value

    def __getitem__(self, key):
        return self._data[str(key).lower()]

    def __delitem__(sel…
13 0 Open

Browse by section

Each section groups closely related Python snippets.

Dictionaries & sets — Python code examples

What you will find here

This page collects dictionaries & sets snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.