Generate all permutations of an alphanumeric string
Sigiloso
def get_permutations(word): if len(word) < 2: yield word return for i in range(len(word)): rest = word[:i] + word[i+1:] for tail in get_permutations(rest): yield word[i] + tail if __name__ == "__main__": got = list( get_permutations("") ) print( got, len(got) ) got = list( get_permutations("n") ) print( got, len(got) ) got = list( get_permutations("no") ) print( got, len(got) ) got = list( get_permutations("non") ) print( got, len(got) ) got = list( get_permutations("none") ) print( got, len(got) )