Skip to content

Instantly share code, notes, and snippets.

@RK11
Created October 26, 2012 21:23
Show Gist options
  • Save RK11/3961640 to your computer and use it in GitHub Desktop.
Save RK11/3961640 to your computer and use it in GitHub Desktop.
All posibilities
def all_posibilities(max_length, letters):
result = []
for length in range(1, max_length+1):
pos = [0]*length
actual_word = ""
limit = (len(letters))**length
nbr_of_words = 0
while nbr_of_words < limit:
for char in range(length):
actual_word = letters[pos[char]] + actual_word
result.append(actual_word)
actual_word = ""
pos[0] += 1
for position in range(len(pos)):
if pos[position] >= len(letters):
pos[position] = 0
try:
pos[position+1] +=1
except IndexError:
break
nbr_of_words += 1
return result
#print all_posibilities(4, ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment