Given a set of permutations return one specific number

Question:

I want your help to catch an specific number or any number that I asked for in bool_check in this case that number is "4321" so i’ve been struggling to get True and also I want the program to show me that specific number from this set of permutations.
For example, I want the output to say:
True
4321
So far i got the permutations and the functions but i dont know how to connect everything. Thank you for your time.

from itertools import product

def bool_check(x):
    
    if x == "4321":
        return True
    else:
        return False

      
def find_key(diferent_dig, quantity_dig):
    
    chars = list(diferent_dig)
    perms = []
    for c in product(chars, repeat = quantity_dig):
        perms.append(c)

        
    return perms

print(find_key("1234", 4))
Asked By: The Vinchi

||

Answers:

product returns a tuple of the items, but you are searching for a string.

Eg. (1, 2, 3, 4) instead of 1234

I am not too sure what you are after but maybe something like this will help:

from itertools import product

def find_key(diferent_dig, quantity_dig):
   chars = list(diferent_dig)
   perms = []
   for c in product(chars, repeat = quantity_dig):
       perms.append(''.join(c)) # Convert from tuple to String
   return perms

print("1234" in find_key("1234", 4)) # returns True
print("5555" in find_key("1234", 4)) # returns False
Answered By: threenplusone
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.