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] Letícia Graziela Demarchi Ferreira #230

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
198 changes: 166 additions & 32 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Your code here\n"
"tup\t= \"I\"\n"
]
},
{
Expand All @@ -33,11 +33,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"type (tup)\n"
]
},
{
Expand All @@ -55,13 +66,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'tup' is not defined",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m tup\u001b[39m.\u001b[39mappend (\u001b[39m\"\u001b[39m\u001b[39moi\u001b[39m\u001b[39m\"\u001b[39m) \u001b[39m# I cant.\u001b[39;00m\n\u001b[0;32m 3\u001b[0m tup \u001b[39m=\u001b[39m (\u001b[39m\"\u001b[39m\u001b[39mI\u001b[39m\u001b[39m\"\u001b[39m,\u001b[39m\"\u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mo\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mn\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mh\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39ma\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mc\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mk\u001b[39m\u001b[39m\"\u001b[39m) \u001b[39m# create a new one\u001b[39;00m\n\u001b[0;32m 5\u001b[0m \u001b[39m# tuples are immutable, i cant do this or otherside i need create a new tup.\u001b[39;00m\n",
"\u001b[1;31mNameError\u001b[0m: name 'tup' is not defined"
]
}
],
"source": [
"# Your code here\n",
"tup.append (\"oi\") # I cant.\n",
"\n",
"tup = (\"I\",\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\") # create a new one\n",
"\n",
"# Your explanation here\n"
"# tuples are immutable, i cant do this or otherside i need create a new tup.\n"
]
},
{
Expand All @@ -79,13 +104,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 21,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n"
]
}
],
"source": [
"# Your code here\n",
"print (tup)\n",
"\n",
"# Your explanation here\n"
"# I able to do this because its possible create a new tup with substitutes the previous value.\n",
"\n"
]
},
{
Expand All @@ -103,11 +137,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('h', 'a', 'o')\n",
"('a', 'o', 'a', 'c')\n"
]
}
],
"source": [
"# Your code here\n"
"tup1 = (\"I\", \"r\", \"o\", \"n\")\n",
"tup2 = (\"h\", \"a\", \"c\", \"k\")\n",
"\n",
"tup1 = tup2[:2] + tup1[2:3]\n",
"tup2 = tup1[-2:]+ tup2 [1:3]\n",
"\n",
"\n",
"print (tup1)\n",
"print (tup2)\n",
"\n"
]
},
{
Expand All @@ -121,11 +173,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 37,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('h', 'a', 'o', 'a', 'o', 'a', 'c')\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = tup1 + tup2\n",
"\n",
"print (tup3)\n"
]
},
{
Expand All @@ -137,11 +199,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 44,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Your code here\n"
"len (tup1)+ len (tup2) #7\n",
"\n",
"len (tup3) #7 too\n"
]
},
{
Expand All @@ -153,11 +228,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 46,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n"
]
}
],
"source": [
"# Your code here\n"
"index_h = tup3.index(\"h\")\n",
"\n",
"print (index_h)\n",
"\n"
]
},
{
Expand All @@ -177,11 +263,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('h', 'a', 'o', 'a', 'o', 'a', 'c')\n",
"True\n",
"False\n",
"True\n",
"False\n",
"False\n"
]
}
],
"source": [
"# Your code here\n"
"print (tup3)\n",
"\n",
"tup3 = ('h', 'a', 'o', 'a', 'o', 'a', 'c')\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)\n",
"\n",
" \n",
"\n"
]
},
{
Expand All @@ -195,11 +306,34 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 55,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a 1\n",
"a 2\n",
"a 3\n",
"c 1\n"
]
}
],
"source": [
"# Your code here\n"
"tup3 = ('h', 'a', 'o', 'a', 'o', 'a', 'c')\n",
"letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n",
"\n",
"for letter in letters:\n",
" count = 0\n",
" for element in tup3:\n",
" if element == letter:\n",
" count +=1\n",
" print (letter, count)\n",
"\n",
"\n",
" # for dentro de for, looping entao a aparece 3 vezes, c aparece 1, os outros nao aparecem. \n",
"\n"
]
}
],
Expand All @@ -219,7 +353,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
Loading