Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
777 B
1
Indexable
Never
queries = ["spede", "deul"]
words = ["duel", "speed", "dule", "cars"]

def generatePermutations(x, start, end, q, init_string):
    string = list(x)
    query_list = list(q)
    if start == end and ''.join(string) == q:
        anagrams[q] = init_string
        print(init_string + " " + q)  
    else:
        for i in range(start, end):
            string[start], string[i] = string[i], string[start]
            generatePermutations(string, start + 1, end, q, init_string)
            string[start], string[i] = string[i], string[start]

def getSearchResults(words, queries):
    # Write your code here
    anagrams = {}
    for q in queries:
        for x in words:
            print(generatePermutations(q, 0, len(q), x, q))

anagrams = {}
getSearchResults(words, queries)