Arrangements and Combinations · Arrangements with Repetitions

Lesson 4

Nikolai Chukhin · Alexander S. Kulikov

Since the words in the previous three problems are not very long, you can simply iterate through all permutations and see how many distinct words result.

from itertools import permutations

for word in ('apple', 'level', 'mississippi'):
    print(len(set(permutations(word, len(word)))))

However, this approach quickly becomes impractical as word length grows. Below, we will come up with a way to find the required count without iterating through all permutations.