One function

product_index in more-itertools/more-itertools

The author described this change as Fix product_index() with iterator input. It counts as a record because the check below fails on the code as it stood at aa8c48008 and passes on cf186b5de, with nothing else changed between the two runs.

Fix saved2025-10-10
Sharing licenceMIT · LICENSE
Change size+1 2

What the code was meant to do, written into the code itself as a docstring

Equivalent to `list(product(*args)).index(element)` The products of *args* can be ordered lexicographically. :func:`product_index` computes the first index of *element* without computing the previous products. `ValueError` will be raised if the given *element* isn't in the product of *args*.

The change

1313 """
1414 elements = tuple(element)
1515 pools = tuple(map(tuple, args))
16- if len(element) != len(args):
16+ if len(elements) != len(pools):
1717 raise ValueError('element is not a product of args')
1818
1919 index = 0
2020 for elem, pool in zip(elements, pools):
2121 index = index * len(pool) + pool.index(elem)
22-
2322 return index

The check that tells the two apart

failpass·tests/test_more.py::ProductIndexTests::test_iterator_input

Check file tests/test_more.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.

Origin and history

The code before itaa8c480086052d4c2a64490d3214e67b7c6e674b
Broken version dated2025-10-09
Modulemore_itertools.more
Units changedproduct_index
Fingerprintd56a47ac809a80e8
Checked2026-08-17 by goldset/0.1

Every field above is generated by our program. None of it is written by hand.

Other bugs found in more-itertools/more-itertools