|
58 | 58 | "cell_type": "code", |
59 | 59 | "execution_count": null, |
60 | 60 | "metadata": {}, |
61 | | - "outputs": [], |
| 61 | + "outputs": [ |
| 62 | + { |
| 63 | + "data": { |
| 64 | + "text/plain": [ |
| 65 | + "True" |
| 66 | + ] |
| 67 | + }, |
| 68 | + "execution_count": 45, |
| 69 | + "metadata": {}, |
| 70 | + "output_type": "execute_result" |
| 71 | + } |
| 72 | + ], |
62 | 73 | "source": [ |
| 74 | + "\n", |
63 | 75 | "# For testing purposes, we will write our code in the function\n", |
64 | 76 | "def anagram_checker(word_a, word_b):\n", |
65 | | - " # Your code here\n", |
| 77 | + " \n", |
| 78 | + " ''' Given two valid strings, check if they are anagrams.\n", |
| 79 | + " anagram_checker is a boolean comparator: \n", |
| 80 | + " True if the two strings are anagrams; False if the two strings are not anagrams.\n", |
| 81 | + " Print message to inddicate whether the two strings are anagrams. '''\n", |
| 82 | + " \n", |
| 83 | + " # Perform an ascending sort of the characters contained in both string arguments\n", |
| 84 | + " word1 = 'word_a'\n", |
| 85 | + " sorted_word1 = sorted(word1)\n", |
| 86 | + " word2 = 'word_b'\n", |
| 87 | + " sorted_word2 = sorted(word2)\n", |
| 88 | + "\n", |
| 89 | + " # Print the two sorted string lists \n", |
| 90 | + " print('String one: ', sorted_word1)\n", |
| 91 | + " print('String two: ', sorted_word2)\n", |
| 92 | + "\n", |
| 93 | + " # Perform a boolean comparison and print the result\n", |
| 94 | + " if word1 == word2:\n", |
| 95 | + " print('The two strings are anagrams of each other')\n", |
| 96 | + " else:\n", |
| 97 | + " print('The two strings are not anagrams.')\n", |
66 | 98 | "\n", |
67 | 99 | "# Run your code to check using the words below:\n", |
68 | 100 | "anagram_checker(\"Silent\", \"listen\")" |
69 | 101 | ] |
70 | 102 | }, |
71 | 103 | { |
72 | 104 | "cell_type": "code", |
73 | | - "execution_count": null, |
| 105 | + "execution_count": 46, |
74 | 106 | "metadata": {}, |
75 | | - "outputs": [], |
| 107 | + "outputs": [ |
| 108 | + { |
| 109 | + "data": { |
| 110 | + "text/plain": [ |
| 111 | + "False" |
| 112 | + ] |
| 113 | + }, |
| 114 | + "execution_count": 46, |
| 115 | + "metadata": {}, |
| 116 | + "output_type": "execute_result" |
| 117 | + } |
| 118 | + ], |
76 | 119 | "source": [ |
77 | 120 | "anagram_checker(\"Silent\", \"Night\")" |
78 | 121 | ] |
79 | 122 | }, |
80 | 123 | { |
81 | 124 | "cell_type": "code", |
82 | | - "execution_count": null, |
| 125 | + "execution_count": 47, |
83 | 126 | "metadata": {}, |
84 | | - "outputs": [], |
| 127 | + "outputs": [ |
| 128 | + { |
| 129 | + "data": { |
| 130 | + "text/plain": [ |
| 131 | + "True" |
| 132 | + ] |
| 133 | + }, |
| 134 | + "execution_count": 47, |
| 135 | + "metadata": {}, |
| 136 | + "output_type": "execute_result" |
| 137 | + } |
| 138 | + ], |
85 | 139 | "source": [ |
86 | 140 | "anagram_checker(\"night\", \"Thing\")" |
87 | 141 | ] |
|
104 | 158 | "def anagram_checker(word_a, word_b, is_case_sensitive):\n", |
105 | 159 | " # Modify your existing code here\n", |
106 | 160 | "\n", |
| 161 | + " \n", |
| 162 | + "\n", |
107 | 163 | "# Run your code to check using the words below:\n", |
108 | 164 | "anagram_checker(\"Silent\", \"listen\", False) # True" |
109 | 165 | ] |
|
130 | 186 | ], |
131 | 187 | "metadata": { |
132 | 188 | "kernelspec": { |
133 | | - "display_name": "new-learner", |
| 189 | + "display_name": "python-env", |
134 | 190 | "language": "python", |
135 | 191 | "name": "python3" |
136 | 192 | }, |
|
144 | 200 | "name": "python", |
145 | 201 | "nbconvert_exporter": "python", |
146 | 202 | "pygments_lexer": "ipython3", |
147 | | - "version": "3.11.8" |
| 203 | + "version": "3.11.13" |
148 | 204 | } |
149 | 205 | }, |
150 | 206 | "nbformat": 4, |
|
0 commit comments