how to use itertools methods so that they show all possible combinations


I need to find absolutely all possible combinations, including taking into account their position.
for example, the combination 222, 200, 220 does not come out in any way. what else can be done?

Here is mu code:

import itertools

real_code = '220'
code = itertools.permutations('012', r=3)
set_of_code = set()
for i in code:
    # print('permut', i)

code2 = itertools.combinations_with_replacement('012', r=3)
for i in code2:
    # print('comboW', i)

for i in set_of_code:
    if i == real_code:
        print('found', i)
    print('not found')


This should give you the desired combinations:

code = itertools.product('012', repeat=3)
Answered By: Max Skoryk
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.