Last active
June 6, 2021 09:55
-
-
Save jin-x/9e0b03bb1c78b9fcae924e1776c91805 to your computer and use it in GitHub Desktop.
@jinxonik / UniLecs #84
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import factorial | |
def anagrams(string): | |
count = {} | |
for ch in string: | |
count[ch] = count[ch]+1 if ch in count else 1 | |
n = factorial(len(string)) | |
for key in count.keys(): | |
if count[key] > 1: n //= factorial(count[key]) | |
return n | |
string = input('Please enter string: ') | |
if len(string) > 10: | |
print('stringing is too long :(') | |
else: | |
print('Total anagrams = %d' % anagrams(string)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment