Skip to content
Open
Changes from 1 commit
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
168 changes: 168 additions & 0 deletions Assignment 1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "6e967208",
"metadata": {},
"source": [
"**Assignment 1**\n",
"*Anagram Checker*"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "cb6f4638",
"metadata": {},
"outputs": [],
"source": [
"def anagram_checker (word1, word2):\n",
" return sorted(word1.lower()) == sorted(word2.lower())"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b71a1985",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print (anagram_checker(\"listen\", \"silent\")\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "80762ea9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(anagram_checker(\"night\", \"THING\"))"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "da5e5a74",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print (anagram_checker(\"Bottom\", \"Top\"))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "b5d10a0a",
"metadata": {},
"outputs": [],
"source": [
"def anagram_checker(word1, word2, is_case_sensitive):\n",
" if is_case_sensitive:\n",
" return sorted(word1) == sorted(word2)\n",
" else:\n",
" return sorted(word1.lower()) == sorted(word2.lower())"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "5f0f55c7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"print(anagram_checker(\"Silent\", \"listen\", False))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "1dccf4df",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(anagram_checker(\"Silent\", \"listen\", True))"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "8e7abaeb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(anagram_checker(\"Silent\", \"Listen\", True))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "python-env",
"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.11.15"
}
},
"nbformat": 4,
"nbformat_minor": 5
}