Metadata-Version: 2.4
Name: itertooldict
Version: 0.1.2
Summary: A missing feature of itertools: labeled product of multiple choices from a dictionary.
Author-email: Eduardo Munoz <emunozgutier@gmail.com>
Project-URL: Homepage, https://github.com/emunozgutier/iterdict
Project-URL: Bug Tracker, https://github.com/emunozgutier/iterdict/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# itertooldict

A missing feature of `itertools`: labeled product of multiple choices from a dictionary.

## Installation

```bash
pip install itertooldict
```

## Usage

`itertooldict` takes a dictionary where values are iterables and yields dictionaries representing their Cartesian product.

```python
from itertooldict import itertooldict

data = {
    "voltage": ["Vmax", "Vmin"],
    "temp": ["hot", "cold"]
}

for combo in itertooldict(data):
    print(combo)

# Output:
# {'voltage': 'Vmax', 'temp': 'hot'}
# {'voltage': 'Vmax', 'temp': 'cold'}
# {'voltage': 'Vmin', 'temp': 'hot'}
# {'voltage': 'Vmin', 'temp': 'cold'}
```

### Excluding Combinations

You can use the `.remove()` method to exclude specific combinations or patterns.

```python
it = itertooldict(data)
it.remove({"voltage": "Vmax", "temp": "hot"})

for combo in it:
    print(combo)
# {'voltage': 'Vmax', 'temp': 'cold'}
# {'voltage': 'Vmin', 'temp': 'hot'}
# {'voltage': 'Vmin', 'temp': 'cold'}
```

You can also remove based on partial matches:

### Randomizing Order

You can randomize the order of the generated combinations:

```python
it = itertooldict(data).random()
for combo in it:
    print(combo) # Order will be shuffled
```

### Updating Key Order

You can specify the order of keys in the resulting dictionaries:

```python
it = itertooldict(data)
it.updateKeyOrder(["temp", "voltage"])
for combo in it:
    print(combo) # {'temp': 'hot', 'voltage': 'Vmax'}, ...
```

### Compatibility with list() and enumerate()

`itertooldict` works seamlessly with standard Python functions:

```python
# Convert to list
all_combos = list(itertooldict(data))

# Use with enumerate
for i, combo in enumerate(itertooldict(data)):
    print(f"{i}: {combo}")
```
