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
216 changes: 186 additions & 30 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup = (\"I\", )"
]
},
{
Expand All @@ -32,11 +33,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'tuple'>\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"print(type(tup))"
]
},
{
Expand All @@ -54,13 +64,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n",
"tup2 = tup + (\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"print(tup)\n",
"\n",
"# Your explanation here\n"
"# Your explanation here\n",
"#Is not possible to do it as tupples are immutable, so it has no attribute append. "
]
},
{
Expand All @@ -80,13 +101,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'tuple'>\n"
]
}
],
"source": [
"# Your code here\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"print(type(tup))\n",
"\n",
"# Your explanation here\n"
"# Your explanation here\n",
"# Tuple data type are immutable so adding new values is not possible, so we can change the class type of the object to string or\n",
"# generate another tupple object. \n"
]
},
{
Expand All @@ -104,11 +137,44 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ironhack\n"
]
}
],
"source": [
"# Your code here\n",
"tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n",
"tup = \"\".join(tup) \n",
"print(tup)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"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(tuple(tup1))\n",
"print(tuple(tup2))"
]
},
{
Expand All @@ -122,11 +188,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 66,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup3 = tup1 + tup2\n",
"print(str(tup3))"
]
},
{
Expand All @@ -138,11 +214,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 53,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"4\n",
"4\n"
]
},
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"count_tup1 = len(tup1)\n",
"print(count_tup1)\n",
"count_tup2 = len(tup2)\n",
"print(count_tup2)\n",
"count_tup3 = len(tup3)\n",
"count_tup3 == count_tup1 + count_tup2"
]
},
{
Expand All @@ -154,11 +255,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 54,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"h\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"i_tup3_h = tup3[4]\n",
"print(i_tup3_h)"
]
},
{
Expand All @@ -178,11 +289,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 77,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"True\n",
"False\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"# remember tup3 ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for i in letters:\n",
" if i in tup3:\n",
" print(\"True\")\n",
"else:\n",
" print(\"False\")\n",
" "
]
},
{
Expand All @@ -203,12 +334,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 94,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'a': 1, 'b': 0, 'c': 1, 'd': 0, 'e': 0}\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup3 = ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"letter_occurrence = {}\n",
"\n",
"for i in letters:\n",
" letter_count = tup3.count(i)\n",
" letter_occurrence[i] = letter_count\n",
"\n",
"print(letter_occurrence)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -227,7 +383,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.11.4"
},
"toc": {
"base_numbering": 1,
Expand Down
Loading