How can I write an algorithm to get all the possible arrangements of the letters in a word? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I write an algorithm to get all the possible arrangements of the letters in a word?

An algorithm to get all the possible arrangements of all the letters in a word or a list of letters, a possible arrangement of all length (from 1 to the length of the word given)

16th Jun 2020, 6:23 AM
Emmanuel Obasanmi
1 Answer
+ 4
For example, there is a special module in Python. from itertools import permutations word = input() list = [] for item in permutations(word): list.append(''.join(item)) print(list) How it works? Please, read the Heap's Algorithm in Wiki and Docs for this module in Python.org😉
17th Jun 2020, 9:11 AM
Anton Popov