Objective
Create a Python program that shows all the distinct anagrams of a word using itertools.permutations.
Instructions
- Import
permutationsfrom theitertoolsmodule. - Read a lower-case word of at most 6 letters.
- Generate all the permutations of its letters, join them back into words (
"".join(p)) and store them in a set to remove the repeated ones. - On the first line show
Anagrams: K, with the number of distinct anagrams. - Then show the anagrams sorted alphabetically, one per line.
abc
Anagrams: 6
abc
acb
bac
bca
cab
cba
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise