Skip to content
kitsuyuiPublic

About

zip and zip_longest for dict

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

dict_zip

zip and zip_longest for dict.

Python PyPI version Coverage License dict-zip

Installation

$ pip install dict-zip

Usage

dict_zip

dict_zip is zip for dict. The result keeps the first dictionary's insertion order and skips keys missing from any dictionary.

>>> from dict_zip import dict_zip
>>> dict_zip({'a': 1, 'b': 2}, {'a': 3, 'b': 4})
{'a': (1, 3), 'b': (2, 4)}

dict_zip_longest

dict_zip_longest is zip_longest for dict. It fills with fillvalue (default: None) when argument dict doesn't have match key. The result keeps keys in the order they are first seen while scanning the input dictionaries from left to right.

>>> from dict_zip import dict_zip_longest
>>> dict_zip_longest({'a': 1, 'b': 2, 'c': 4}, {'a': 3, 'b': 4})
{'a': (1, 3), 'b': (2, 4), 'c': (4, None)}

map_keys, map_values, map_items

map_keys, map_values, and map_items are used to map keys, values, and items of dict.

>>> from dict_zip import map_keys
>>> map_keys({'a': 1, 'b': 2}, str.upper)
{'A': 1, 'B': 2}
>>> from dict_zip import map_values
>>> map_values({'a': 1, 'b': 2}, str)
{'a': '1', 'b': '2'}
>>> from dict_zip import map_items
>>> map_items({'a': 1, 'b': 2}, str.upper, str)
{'A': '1', 'B': '2'}

map_items accepts the key mapper as the second positional argument. The keyword-only func= argument is kept as a backward-compatible alias for key_func.

tuple_keys

tuple_keys is used to convert dict keys to tuple.

>>> from dict_zip import tuple_keys
>>> tuple_keys({'a': 1, 'b': 2})
{('a',): 1, ('b',): 2}

Type hints

dict_zip supports for type hints.

screen-shot-of-type-hints

Development

This repository uses lefthook to run the same checks as CI locally, so problems surface before they reach CI.

# Install dependencies
uv sync

# Install the Git hooks (once; requires lefthook on your PATH)
lefthook install

Once installed, the hooks run automatically:

  • pre-commit: uv run poe check
  • pre-push: uv run poe check and uv run poe test

You can also run the checks manually:

uv run poe check
uv run poe test

CI still runs the full matrix (see .github/workflows/); the hooks only bring that feedback earlier on your machine.

LICENSE

The 3-Clause BSD License. See also LICENSE file.

About

zip and zip_longest for dict

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages