Skip to content
Open
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
182 changes: 163 additions & 19 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,38 @@
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"students = [\"student1\", \"student2\", \"student3\", \"student4\", \"student5\"]\n",
"grades = []\n",
"for student in students:\n",
" grade = int(input(f\"what is the grade of {student}?\"))\n",
" grades.append(grade)\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the grades are [6, 7, 5, 8, 10]\n",
"the sum of total grades is : 36\n",
"[5, 6, 10]\n",
"the len is : 3\n",
"1\n"
]
}
],
"source": [
"total_grades = sum(grades)\n",
"print(\"the grades are \", grades)\n",
"print(\"the sum of total grades is : \",total_grades)\n",
"new_list = sorted(grades[0:6:2])\n",
"print(new_list)\n",
"print(\"the len is :\", len(new_list))\n",
"print(new_list.count(5))"
]
},
{
Expand Down Expand Up @@ -95,11 +126,42 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 35,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"apple\n",
"orange\n",
"('apple', 'lemmon', 'cherry', 'mango', 'orange')\n",
"('apple', 'lemmon', 'cherry', 'mango', 'orange', 'grape', 'kiwi')\n",
"the first part is :('apple', 'lemmon', 'cherry'). and the second is ('mango', 'orange', 'grape')\n",
"7\n"
]
}
],
"source": [
"# Your code here"
"fruits = (\"apple\", \"banana\", \"cherry\", \"mango\", \"orange\")\n",
"print(fruits[0])\n",
"print(fruits[-1])\n",
"\n",
"list_fruits = list(fruits)\n",
"list_fruits[1] = \"lemmon\"\n",
"fruits = tuple(list_fruits)\n",
"print(fruits)\n",
"\n",
"new_fruits =(\"grape\", \"kiwi\")\n",
"fruits = fruits + new_fruits\n",
"print(fruits)\n",
"\n",
"first_part = fruits[0:3]\n",
"second_part = fruits[3:6]\n",
"print(f\"the first part is :{first_part}. and the second is {second_part}\")\n",
"\n",
"print(len(fruits))\n",
"\n"
]
},
{
Expand Down Expand Up @@ -136,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -163,13 +225,58 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 57,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"the len of words1 is : 41\n",
"the len of words2 is : 46\n",
"uique words in poem {'the', 'in', 'hold', 'some', 'great', 'tasted', 'favor', 'hate', 'will', 'twice', 'i', 'ice', 'world', 'fire', 'perish', 'would', 'also', 'destruction', 'desire', 'from', 'suffice', 'for', 'i’ve'}\n",
"uique words in new poem {'seen', 'away,', 'are', 'dream,', \"I've\", 'quest.', 'But', 'as', 'deem,', 'still', 'side', 'a', 'test.', 'today,', 'life', 'I', 'fades', 'we', 'From', 'To', \"It's\", 'love,', 'though', 'Some', 'see', 'made', 'of.', \"it's\"}\n",
"['But', 'From', 'I', \"I've\", \"It's\", 'Some', 'To', 'a', 'and', 'are', 'as', 'away,', 'but', 'deem,', 'dream,', 'end', 'enough', 'fades', 'had', 'if', 'is', 'it', \"it's\", 'know', 'life', 'love,', 'made', 'of', 'of.', 'quest.', 'say', 'see', 'seen', 'side', 'still', 'test.', 'that', 'think', 'those', 'though', 'to', 'today,', 'we', 'what', 'who', 'with']\n"
]
}
],
"source": [
"# Your code here"
"poem1 = poem.replace(\",\", \"\").replace(\".\", \"\").lower()\n",
"poem2 = new_poem.replace(\",\", \"\").replace(\".\", \"\").lower()\n",
"\n",
"words1 = poem1.split()\n",
"words2 = new_poem.split()\n",
"\n",
"set1 = set(words1)\n",
"set2 = set(words2)\n",
"\n",
"print(f\"the len of words1 is :\",len(set1))\n",
"print(f\"the len of words2 is :\",len(set2))\n",
"\n",
"unique1 = set1 - set2\n",
"unique2 = set2 - set1\n",
"print(\"uique words in poem\", set1 - set2)\n",
"print(\"uique words in new poem\", set2 - set1)\n",
"\n",
"commen_words = sorted(set1) and sorted(set2)\n",
"print(commen_words)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"87\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -193,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -202,11 +309,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 60,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100}}\n"
]
}
],
"source": [
"# Your code here"
"grades[\"Bob\"][\"Philosophy\"] = 100\n",
"print(grades)"
]
},
{
Expand Down Expand Up @@ -239,13 +355,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 62,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}\n"
]
}
],
"source": [
"keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n",
"values = [75, 85, 60,90]\n",
"student_grades = {} \n",
"for key, value in zip(keys,values):\n",
" student_grades[key] = value\n",
"\n",
"print(student_grades)\n",
"# Your code here"
]
},
Expand Down Expand Up @@ -275,17 +403,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"60\n"
]
}
],
"source": [
"# Your code here"
"min_student = min(student_grades.values())\n",
"print(min_student)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "base",
"language": "python",
"name": "python3"
},
Expand All @@ -299,7 +443,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down