Question d’entretien chez Yelp

Generate all permutations of an alphanumeric string

Réponses aux questions d'entretien

Utilisateur anonyme

2 févr. 2014

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) )

1

Utilisateur anonyme

4 janv. 2013

pseudocode