curriculum/challenges/english/blocks/daily-coding-challenges-python/69162d64f96574d9bb629f01.md
Given a string, return the number of distinct permutations that can be formed from its characters.
A-Z, a-z).For example, given "abb", return 3 because there's three unique ways to arrange the letters: "abb", "bab", and "bba".
count_permutations("abb") should return 3.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_permutations("abb"), 3)`)
}})
count_permutations("abc") should return 6.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_permutations("abc"), 6)`)
}})
count_permutations("racecar") should return 630.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_permutations("racecar"), 630)`)
}})
count_permutations("freecodecamp") should return 39916800.
({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(count_permutations("freecodecamp"), 39916800)`)
}})
def count_permutations(s):
return s
from math import factorial
from collections import Counter
def count_permutations(s):
freq = Counter(s)
n = len(s)
result = factorial(n)
for count in freq.values():
result //= factorial(count)
return result