Anagram

Jason Orendorff jason at jorendorff.com
Wed Jan 23 09:07:16 EST 2002


Nikolai Kirsebom wrote:
> Friend of mine who used to work with lisp (and is a bit interested in
> Python) asked me how compact I could write a program to evaluate the
> number of possible combinations a set of characters (string) can be
> written in - handling two identical characters as different
> characters.

Python's strength is not "how compact" but "how clear".

The number you want is the factorial of the length of the string.

import sys

def f(n):
    if n < 2:  return 1
    return n * f(n-1)

for a in sys.argv[1:]:
    print a, f(len(a))

## Jason Orendorff    http://www.jorendorff.com/




More information about the Python-list mailing list