Answer To: aa aah aahed aahing aahs aal aalii aaliis aals aardvark aardvarks aardwolf aardwolves aas aasvogel...
Sandeep Kumar answered on Oct 24 2021
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"from time import localtime\n",
"#add others here"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def print_explanation():\n",
" print(\n",
" '''\n",
" An anagram is a word or phrase formed by rearranging the letters of a different word or phrase, \n",
" typically using all the original letters exactly once. It can however us on a few of the letters. \n",
" A palindrome is a word, number, phrase, or other sequence of characters which reads the same \n",
" backward as forward, such as \"madam\" or \"racecar\".\n",
" \n",
" A palingram – a letter palingram. A palingram can also be created using syllables\n",
" or words, in addition to individual letters. An example of this using words is, “He was, was he?” \n",
" Notice that the words can be reversed and the sentence still reads the same. \n",
" A sentence that is a palingram and a palindrome is, “I did, did I” \n",
" \n",
" This application allows three activities.\n",
" \n",
" Activity A: Finds the anagrams for any word you enter. Then identifies palindromes, if there are any, \n",
" in the identified anagrams. \n",
" \n",
" Activity B: Finds all the word pairs in the dictionary list which form palingrams. \n",
" The palingrams ignore spaces and hyphens. \n",
" \n",
" Activity C: Find all the palindromes in the dictionary.\n",
" ''')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def load(file_path):\n",
" \"\"\"Open a text file & turn contents into a list of lowercase strings.\"\"\"\n",
" try:\n",
" with open(file_path) as in_file:\n",
" loaded_txt = in_file.read().strip().split('\\n')\n",
" loaded_txt = [x.lower() for x in loaded_txt]\n",
" return loaded_txt\n",
" except IOError as e:\n",
" print(\"{}\\nError opening {}. Terminating program.\".format(e, file),\n",
" file_path=sys.stderr)\n",
" sys.exit(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def find_anagrams(word_for_search, search_list_dictionary):\n",
" anagrams_list = []\n",
" for word in search_list_dictionary:\n",
" if sorted(word_for_search.lower()) == sorted(word.lower()) and word_for_search.lower() != word.lower():\n",
" anagrams_list.append(word)\n",
" return anagrams_list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def find_palingrams(dictionary_list):\n",
" palingrams_array = []\n",
" for word_1 in dictionary_list:\n",
" for word_2 in dictionary_list:\n",
" check_palingrams = word_1 +...