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
222 changes: 191 additions & 31 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 66,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I',)\n"
]
}
],
"source": [
"# Your code here\n"
"# Your code here\n",
"tup=(\"I\",)\n",
"print(tup)"
]
},
{
Expand All @@ -32,11 +42,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 67,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"type(tup)\n"
]
},
{
Expand All @@ -54,13 +75,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" We can't add or update a tuple as we just have two methods: count and index. But we can use some workarounds to do it: adding a tuple as new tuple using list (some in-out from tuple to list a create tuple again)\n",
"\n"
]
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"#workaround\n",
"\n",
"tup_lst = list(tup)\n",
"lst_aux = [\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n",
"for i in lst_aux:\n",
" tup_lst.append(i)\n",
"tup = tuple(tup_lst)\n",
"print(tup)\n",
"print()\n",
"\n",
"# Your explanation here\n",
"\n",
"print(''' We can't add or update a tuple as we just have two methods: count and index. But we can use some workarounds to do it: adding a tuple as new tuple using list (some in-out from tuple to list a create tuple again)\n",
"''')"
]
},
{
Expand All @@ -80,13 +123,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 69,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
},
{
"data": {
"text/plain": [
"tuple"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n",
"\n",
"# Your explanation here\n"
"lst1 = [\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\"]\n",
"tup = tuple(lst1)\n",
"print(tup)\n",
"type(tup)\n",
"\n",
"# Your explanation here\n",
"\n",
"#we can cast a list as tuple to replace existing tuple.\n"
]
},
{
Expand All @@ -104,11 +172,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 40,
"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",
"print(tup1)\n",
"print(tup2)"
]
},
{
Expand All @@ -122,11 +202,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tup: ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n",
"Tup3: ('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = (tup1+tup2)\n",
"print(\"Tup:\",tup)\n",
"print(\"Tup3:\",tup3)"
]
},
{
Expand All @@ -138,11 +229,37 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tup1 4 elements\n",
"tup2 4 elements\n",
"Total tup1+tup2 8 elements\n",
"tup3 8 elements\n"
]
}
],
"source": [
"# Your code here\n"
"counter1 =0\n",
"counter2 = 0\n",
"counter3 = 0\n",
"\n",
"for i in tup1:\n",
" counter1+=1\n",
"print(\"tup1\",counter1,\"elements\")\n",
"for i in tup2:\n",
" counter2+=1\n",
"print(\"tup2\",counter2,\"elements\")\n",
"print(\"Total tup1+tup2\",counter1+counter2,\"elements\")\n",
"\n",
"for i in tup3:\n",
" counter3+=1\n",
"print(\"tup3\",counter3,\"elements\")\n",
"\n"
]
},
{
Expand All @@ -154,11 +271,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 65,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"index is 4\n",
"4\n"
]
}
],
"source": [
"# Your code here\n"
"print(tup3.index('h'))"
]
},
{
Expand All @@ -178,11 +304,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 63,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a True\n",
"b False\n",
"c True\n",
"d False\n",
"e False\n"
]
}
],
"source": [
"# Your code here\n"
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"for i in letters:\n",
" print(i,i in tup3)"
]
},
{
Expand All @@ -203,12 +343,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 64,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a 1\n",
"b 0\n",
"c 1\n",
"d 0\n",
"e 0\n"
]
}
],
"source": [
"# Your code here\n"
"for i in letters:\n",
" print(i,tup3.count(i))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -227,7 +387,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.11.4"
},
"toc": {
"base_numbering": 1,
Expand Down
Loading