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

[lab-tuple-set-dict] Joao Soares #219

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
187 changes: 158 additions & 29 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup = (\"I\",)"
]
},
{
Expand All @@ -33,11 +34,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"type(tup)"
]
},
{
Expand All @@ -55,13 +68,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"# Nocode\n",
"\n",
"# Your explanation here\n",
"\n",
"# You can't append elements to tuples since they are immutable"
]
},
{
Expand All @@ -79,13 +96,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"tup = tup + (\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"print(tup)\n",
"\n",
"# Your explanation here\n",
"## Since tuples are immutable, we can create a new tuple with the previous elements plus the new elements we wish to add."
]
},
{
Expand All @@ -103,11 +132,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n')\n",
"('h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = tup[:4]\n",
"tup2 = tup[-4:]\n",
"\n",
"print(tup1)\n",
"print(tup2)"
]
},
{
Expand All @@ -121,11 +163,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"tup3 and tup are the same\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup3 = tup1 + tup2\n",
"print(tup3) # (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"\n",
"if tup3 == tup:\n",
" print(\"tup3 and tup are the same\")\n",
"else:\n",
" print(\"tup3 and tup are not the same\")"
]
},
{
Expand All @@ -137,11 +195,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup1 has 4 elements, and tup2 has 4\n",
"The the result of the sum of tup1 and tup2 is the same as the total letters in tup 3\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"count1 = len(tup1)\n",
"count2 = len(tup2)\n",
"\n",
"print(\"tup1 has\",count1,\"elements, and tup2 has\",count2)\n",
"\n",
"if count1 + count2 == len(tup3):\n",
" print(\"The the result of the sum of tup1 and tup2 is the same as the total letters in tup 3\")\n",
"else:\n",
" print(\"The result of the sum of tup1 and tup2 is not the same as the total letters in tup 3\")"
]
},
{
Expand All @@ -153,11 +229,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"print(tup3.index(\"h\"))"
]
},
{
Expand All @@ -177,11 +262,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 25,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a is in tup3: True\n",
"b is in tup3: False\n",
"c is in tup3: True\n",
"d is in tup3: False\n",
"e is in tup3: False\n"
]
}
],
"source": [
"# Your code here\n"
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"for x in letters:\n",
" if x in tup3:\n",
" print(x, \"is in tup3:\", True)\n",
" else:\n",
" print(x, \"is in tup3:\", False)"
]
},
{
Expand All @@ -195,12 +297,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a appears 1 time(s) in tup3\n",
"b appears 0 time(s) in tup3\n",
"c appears 1 time(s) in tup3\n",
"d appears 0 time(s) in tup3\n",
"e appears 0 time(s) in tup3\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"for letter in letters:\n",
" count = tup3.count(letter)\n",
" print(letter, \"appears\", count, \"time(s) in tup3\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -219,7 +343,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.10.7"
},
"vscode": {
"interpreter": {
"hash": "721db305ef1fd1fc91cdf20e400af694a949fe540ac5f48c160f31c7e384879d"
}
}
},
"nbformat": 4,
Expand Down
Loading