Skip to content
Open
Show file tree
Hide file tree
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
113 changes: 51 additions & 62 deletions M1_Python/d4_Strings_and_files/Into to Python - part 6.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -533,23 +533,13 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Aph t t\n"
]
}
],
"outputs": [],
"source": [
"# String cleaning function\n",
"def clean_string(string):\n",
" \n",
"\n",
"clean_string(\"Aph@t 100t\")"
" pass"
]
},
{
Expand Down Expand Up @@ -1016,21 +1006,35 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Never gonna give you up\n",
"Never gonna let you down\n",
"Never gonna run around and desert you\n"
"a string\n"
]
}
],
"source": [
"# Distilling text.\n"
"# Distilling text.\n",
"text = \"[a]n example[ string]\"\n",
"\n",
"distilled = \"\"\n",
"inside = False\n",
"for c in text:\n",
" if c == \"[\":\n",
" inside = True\n",
" continue\n",
" if c == \"]\":\n",
" inside = False\n",
" continue\n",
" \n",
" if inside == True:\n",
" distilled += c\n",
" \n",
"print(distilled)"
]
},
{
Expand All @@ -1042,7 +1046,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 8,
"metadata": {},
"outputs": [
{
Expand All @@ -1055,7 +1059,14 @@
}
],
"source": [
"# ROTR-13\n"
"# ROTR-13\n",
"import string \n",
"alphabet = string.ascii_uppercase\n",
"split_alphabet = alphabet[13:]+ alphabet[0:13]\n",
"\n",
"print(alphabet)\n",
"print(split_alphabet)\n",
"\n"
]
},
{
Expand All @@ -1067,36 +1078,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"text = \"\"\"How much wood would a woodchuck chuck\n",
"If a woodchuck could chuck wood?\n",
"He would chuck, he would, as much as he could,\n",
"And chuck as much as a woodchuck would\n",
"If a Mr. Smith could chuck wood\\n\\r\\t.\"\"\"\n",
"\n",
"# read whole text\n",
"# create a counter\n",
"# get rid \\n\n",
"# get rid of ?. special grammar\n",
"# lowercase my sentence\n",
"\"if a woodchuck could chuck wood\"\n",
"# split the string by some character\n",
"[\"if\", \"a\", \"woodchuck\"]\n",
"#check if wood is in the list\n",
" # if yes\n",
" # counter = counter +1 <--> counter += 1 \n",
" # else\n",
" #pass\n",
"#return\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -1105,22 +1087,29 @@
"3"
]
},
"execution_count": 13,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Counting wood.\n",
"def wood_counter(text):\n",
" text = text.replace(\"?\", \"\").replace(\".\",\"\").replace().replace\n",
" l = text.lower().strip().split()\n",
" counter = 0\n",
" for word in l:\n",
" if word == \"wood\":\n",
" counter +=1\n",
" return counter\n",
"wood_counter(text)"
"text = \"\"\"How much wood would a woodchuck chuck\n",
"If a woodchuck could chuck wood?\n",
"He would chuck, he would, as much as he could,\n",
"And chuck as much as a woodchuck would\n",
"If a Mr. Smith could chuck wood\\n\\r\\t.\"\"\"\n",
"\n",
"\n",
"def get_wood(text):\n",
" strip_qm = text.replace(\"?\", \"\")\n",
" get_words = [word.lower() for word in strip_qm.split() if word.isalnum()]\n",
" count_wood = 0 \n",
" for word in get_words:\n",
" if word == 'wood':\n",
" count_wood += 1\n",
" return count_wood\n",
"\n",
"get_wood(text)\n"
]
},
{
Expand Down Expand Up @@ -1559,7 +1548,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Loading