forked from UofT-DSI/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Assignment #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Alexfom0412
wants to merge
1
commit into
main
Choose a base branch
from
assignment-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Assignment #1
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,32 +56,79 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "execution_count": 40, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "True" | ||
| ] | ||
| }, | ||
| "execution_count": 40, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "# For testing purposes, we will write our code in the function\n", | ||
| "def anagram_checker(word_a, word_b):\n", | ||
| " # Your code here\n", | ||
| " \n", | ||
| "# Checking string lengths to see if they can be anagrams\n", | ||
| " if len (word_a) != len (word_b):\n", | ||
| " return False\n", | ||
| " else:\n", | ||
| "# Converting strings to lower-case\n", | ||
| " word_a = word_a.lower()\n", | ||
| " word_b = word_b.lower()\n", | ||
| "\n", | ||
| "# Sorting characters in both strings\n", | ||
| " sorted_word_a = sorted(word_a)\n", | ||
| " sorted_word_b = sorted(word_b)\n", | ||
| "\n", | ||
| "# If sorted strings are the same, return True \n", | ||
| " return sorted_word_a == sorted_word_b\n", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the codes can be consolidated to one line: |
||
| "\n", | ||
| "# Run your code to check using the words below:\n", | ||
| "anagram_checker(\"Silent\", \"listen\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "execution_count": 41, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "False" | ||
| ] | ||
| }, | ||
| "execution_count": 41, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "anagram_checker(\"Silent\", \"Night\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "execution_count": 8, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "True" | ||
| ] | ||
| }, | ||
| "execution_count": 8, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "anagram_checker(\"night\", \"Thing\")" | ||
| ] | ||
|
|
@@ -97,22 +144,60 @@ | |
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "execution_count": 42, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "True" | ||
| ] | ||
| }, | ||
| "execution_count": 42, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "def anagram_checker(word_a, word_b, is_case_sensitive):\n", | ||
| " # Modify your existing code here\n", | ||
| " \n", | ||
| " # Checking string lengths to see if they can be anagrams\n", | ||
| " if len (word_a) != len (word_b):\n", | ||
| " return False\n", | ||
| " else:\n", | ||
| " \n", | ||
| " # Converting strings to lower-case if not case-sensitive strings required\n", | ||
| " if not is_case_sensitive:\n", | ||
| " word_a = word_a.lower()\n", | ||
| " word_b = word_b.lower()\n", | ||
| " \n", | ||
| " # Sorting characters in both strings\n", | ||
| " sorted_word_a = sorted(word_a)\n", | ||
| " sorted_word_b = sorted(word_b)\n", | ||
| "\n", | ||
| "## If sorted strings are the same, return True \n", | ||
| " return sorted_word_a == sorted_word_b\n", | ||
| "\n", | ||
| "# Run your code to check using the words below:\n", | ||
| "anagram_checker(\"Silent\", \"listen\", False) # True" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "execution_count": 43, | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "False" | ||
| ] | ||
| }, | ||
| "execution_count": 43, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "source": [ | ||
| "anagram_checker(\"Silent\", \"Listen\", True) # False" | ||
| ] | ||
|
|
@@ -130,7 +215,7 @@ | |
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "new-learner", | ||
| "display_name": "dsi_participant", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
|
|
@@ -144,7 +229,7 @@ | |
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.11.8" | ||
| "version": "3.9.21" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not necessary, but good thinking!