Skip to content
pramode edited this page Aug 12, 2011 · 1 revision

Write a Python program which will read a text file containing english words and prints out a list of "anagrams".

Example: suppose the text file contains the following words:

       hello
       eat
       ant
       tea
       old
       ate

The output should be:

       hello
       eat tea ate
       ant
       old

"eat", "tea" and "ate" are anagrams (they contain the same alphabets arranged in different permutations).

Each line of your output will contain only one word if that word does not have any anagrams in the file. Otherwise, all the anagrams of the word should be displayed on the same line. The order in which the words are displayed does not matter.

Hint: you can use a Python dictionary; you can also think of sorting ...