Unexpected result when using nested loops with Python's itertools.product for cartesian product generation
I'm updating my dependencies and I'm prototyping a solution and I'm optimizing some code but I've been struggling with this for a few days now and could really use some help. I've been trying to generate the cartesian product of two lists using `itertools.product`, but I'm getting unexpected results when I try to process the output with nested loops. My goal is to combine the elements from two lists into all possible pairs, but I seem to be duplicating some entries in the final output. Here's what I have: ```python from itertools import product a = [1, 2] b = ['x', 'y'] combinations = list(product(a, b)) for i in range(len(combinations)): for j in range(len(combinations)): if combinations[i][0] == combinations[j][0] and i != j: print(f'Duplicate found: {combinations[i]} and {combinations[j]}') else: print(f'Storing pair: {combinations[i]} and {combinations[j]}') ``` I expected to see the combinations printed without duplicates, but I'm seeing pairs being flagged incorrectly as duplicates. The output shows pairs like `(1, 'x') and (1, 'y')` being processed as different entities, which I didn’t anticipate. I’ve tried changing the condition inside the inner loop to only check for the second element of the pairs as well, but I still encounter issues with what I thought should be unique pairs. My understanding was that the output from `itertools.product` should give me all unique combinations, yet my nested iteration seems to contradict that. I'm using Python 3.9.1. Is there a better way to loop through these combinations that would avoid this duplication issue? Am I misunderstanding something about how `product` works or how to loop through the generated pairs effectively? This is part of a larger API I'm building. Am I missing something obvious? This issue appeared after updating to Python 3.11. Any examples would be super helpful. This is my first time working with Python 3.9.