Original code copyright (C) 2009-2022 Rudolf Cardinal (

This file is part of cardinal_pythonlib.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Iteration assistance functions.

cardinal_pythonlib.iterhelp.product_dict(**kwargs: Iterable) Iterable[Dict][source]


Takes keyword arguments, and yields dictionaries containing every combination of possibilities for each keyword.


>>> list(product_dict(a=[1, 2], b=[3, 4]))
[{'a': 1, 'b': 3}, {'a': 1, 'b': 4}, {'a': 2, 'b': 3}, {'a': 2, 'b': 4}]

>>> list(product_dict(a="x", b=range(3)))
[{'a': 'x', 'b': 0}, {'a': 'x', 'b': 1}, {'a': 'x', 'b': 2}]

>>> product_dict(a="x", b=range(3))
<generator object product_dict at 0x7fb328070678>