Skip to content

Instantly share code, notes, and snippets.

@jin-x
Last active June 6, 2021 09:55
Show Gist options
  • Save jin-x/9e0b03bb1c78b9fcae924e1776c91805 to your computer and use it in GitHub Desktop.
Save jin-x/9e0b03bb1c78b9fcae924e1776c91805 to your computer and use it in GitHub Desktop.
@jinxonik / UniLecs #84
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