Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions 02_activities/assignments/assignment_1_done.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Student : Hamed Abangar\n",
"\n",
"Assignment 1 :"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Part 1: Building the base Anagram Checker\n",
"Given two valid strings, check to see if they are anagrams of each other. If it is, return True, else False. For this part, we can assume that uppercase letters are the same as if it was a lowercase character."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(string1, string2):\n",
" # Convert both strings to lowercase\n",
" string1 = string1.lower()\n",
" string2 = string2.lower()\n",
" \n",
" # Sort the characters and compare\n",
" return sorted(string1) == sorted(string2)\n",
"\n",
"anagram_checker('hamed','DaHmE')\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker('Book','Kobe')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Part 2: Expanding the functionality of the Anagram Checker\n",
"Using your existing and functional anagram checker, let's add a boolean option called is_case_sensitive, which will return True or False based on if the two compared words are anagrams and if we are checking for case sensitivity."
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def anagram_checker(string1, string2, check_case_sensitive=False):\n",
" # Convert strings to lower case if case sensitiveness is not important\n",
" if not check_case_sensitive:\n",
" string1 = string1.lower()\n",
" string2 = string2.lower()\n",
" \n",
" # Compare sorted characters\n",
" return sorted(string1) == sorted(string2)\n",
"\n",
"#run with default value\n",
"anagram_checker('hamed','meHda')"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker('hamed','meHda',False)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker('listen','siLEnt',False)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"anagram_checker('listen','siLEnt',True)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.19"
}
},
"nbformat": 4,
"nbformat_minor": 2
}