Skip to content
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

[Tuple Set Dict Lab] Pedro Faria Blanc #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
197 changes: 169 additions & 28 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +35,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"type(tup)"
]
},
{
Expand All @@ -55,13 +70,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = [\"I\",]\n",
"tup.append(\"r\")\n",
"tup.append(\"o\")\n",
"tup.append(\"n\")\n",
"tup.append(\"h\")\n",
"tup.append(\"a\")\n",
"tup.append(\"c\")\n",
"tup.append(\"k\")\n",
"\n",
"\n",
"# Your explanation here\n",
"\n",
"#Tuples are immutable, which means their values cannot be changed after they are created.\n",
"#However, we can append one element at a time."
]
},
{
Expand All @@ -79,13 +107,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"# Your explanation here\n",
"\n",
"# Tuples are a data type which is actually immutable, this means that they cannot be changed once created."
]
},
{
Expand All @@ -103,11 +133,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup1: ('I', 'r', 'o', 'n')\n",
"tup2: ('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"# define the tuple once again\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"# since you can't use the method split() in tuples, reassign new variables called tup1 and tup2\n",
"tup1 = tup[:4]\n",
"tup2 = tup[-4:]\n",
"\n",
"# now print\n",
"print(\"tup1:\", tup1)\n",
"print(\"tup2:\", tup2)\n"
]
},
{
Expand All @@ -121,11 +171,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup3 and tup are equal\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"tup3 = tup1 + tup2\n",
"\n",
"tup3\n",
"\n",
"if tup3 == tup:\n",
" print(\"tup3 and tup are equal\")"
]
},
{
Expand All @@ -137,11 +202,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of elements in tup1: 4\n",
"Number of elements in tup2: 4\n",
"Number of elements in tup3: 8\n",
"True\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"count_tup1 = len(tup1)\n",
"count_tup2 = len(tup2)\n",
"count_tup3 = len(tup3)\n",
"\n",
"print(\"Number of elements in tup1:\", count_tup1)\n",
"print(\"Number of elements in tup2:\", count_tup2)\n",
"print(\"Number of elements in tup3:\", count_tup3)\n",
"\n",
"if count_tup1 + count_tup2 == count_tup3:\n",
" print(\"True\")"
]
},
{
Expand All @@ -153,11 +240,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"index_of_h = tup3.index(\"h\")\n",
"\n",
"print(index_of_h)"
]
},
{
Expand All @@ -177,11 +276,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"False\n",
"True\n",
"False\n",
"False\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for letter in letters:\n",
" if letter in tup3:\n",
" print(True)\n",
" else:\n",
" print(False)"
]
},
{
Expand All @@ -195,11 +314,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The letter 'a' appears 1 time(s) in tup3\n",
"The letter 'b' appears 0 time(s) in tup3\n",
"The letter 'c' appears 1 time(s) in tup3\n",
"The letter 'd' appears 0 time(s) in tup3\n",
"The letter 'e' appears 0 time(s) in tup3\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"\n",
"tup3 = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for letter in letters:\n",
" count = 0\n",
" for char in tup3:\n",
" if char == letter:\n",
" count += 1\n",
" print(f\"The letter '{letter}' appears {count} time(s) in tup3\")\n"
]
}
],
Expand All @@ -219,7 +360,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
Loading