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
280 changes: 259 additions & 21 deletions lab-python-data-structures.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,76 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Your code here"
"# Your code here\n",
"\n",
"grades = []\n",
"\n",
"grades.append(int(input(\"Enter the grade for student 1: \")))\n",
"grades.append(int(input(\"Enter the grade for student 2: \")))\n",
"grades.append(int(input(\"Enter the grade for student 3: \")))\n",
"grades.append(int(input(\"Enter the grade for student 4: \")))\n",
"grades.append(int(input(\"Enter the grade for student 5: \")))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Total sum of grades: 35\n"
]
}
],
"source": [
"total_sum = sum(grades)\n",
"print(\"Total sum of grades:\", total_sum)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"selected_grades = grades[0:5:2]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"selected_grades.sort()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Selected grades: [6, 8, 9]\n",
"Length of selected grades: 3\n",
"Number of times grade 5 appears: 0\n"
]
}
],
"source": [
"print(\"Selected grades:\", selected_grades)\n",
"print(\"Length of selected grades:\", len(selected_grades))\n",
"print(\"Number of times grade 5 appears:\", selected_grades.count(5))"
]
},
{
Expand Down Expand Up @@ -95,11 +160,110 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"apple pear\n"
]
}
],
"source": [
"# Your code here\n",
"\n",
"fruits = (\"apple\", \"banana\", \"grape\", \"orange\", \"pear\")\n",
"\n",
"firtst_fruit = fruits[0]\n",
"last_fruit = fruits[-1]\n",
"\n",
"print(firtst_fruit, last_fruit)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('apple', 'kiwi', 'grape', 'orange', 'pear')\n"
]
}
],
"source": [
"fruits_list = list(fruits)\n",
"fruits_list[1] = \"kiwi\"\n",
"fruits = tuple(fruits_list)\n",
"\n",
"print(fruits)\n"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('apple', 'kiwi', 'grape', 'orange', 'pear', 'mango', 'pineapple')\n"
]
}
],
"source": [
"# Your code here"
"new_fruits = (\"mango\", \"pineapple\")\n",
"fruits = fruits + new_fruits\n",
"\n",
"print(fruits)\n"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('apple', 'kiwi', 'grape')\n",
"('orange', 'pear', 'mango')\n"
]
}
],
"source": [
"fruits1 = fruits[:3]\n",
"fruits2 = fruits[3:6]\n",
"\n",
"print(fruits1)\n",
"print(fruits2)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"13\n",
"('apple', 'kiwi', 'grape', 'orange', 'pear', 'mango', 'pineapple', 'apple', 'kiwi', 'grape', 'pear', 'mango', 'pineapple')\n"
]
}
],
"source": [
"ultimate_fruit = fruits + fruits1 + fruits2\n",
"lenght_ultimate = len(ultimate_fruit)\n",
"print(lenght_ultimate)\n",
"print(ultimate_fruit)"
]
},
{
Expand Down Expand Up @@ -136,7 +300,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -163,11 +327,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 36,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"41\n",
"42\n",
"{'desire', 'in', 'the', 'for', 'fire', 'suffice', 'hold', 'perish', 'also', 'would', 'favor', 'hate', 'twice', 'destruction', 'world', 'tasted', 'ice', 'great', 'will'}\n",
"{'see', 'we', 'test', 'today', 'still', 'away', 'quest', 'love', 'life', 'are', 'deem', 'as', 'made', 'dream', 'a', 'side', 'its', 'fades', 'seen', 'though'}\n",
"['and', 'but', 'end', 'enough', 'from', 'had', 'i', 'if', 'is', 'it', 'ive', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"\n",
"poem_clean = poem.lower().replace(\",\", \"\").replace(\".\", \"\").replace(\"’\", \"\").replace(\"'\", \"\")\n",
"new_poem_clean = new_poem.lower().replace(\",\", \"\").replace(\".\", \"\").replace(\"’\", \"\").replace(\"'\", \"\")\n",
"\n",
"poem_set = set(poem_clean.split())\n",
"new_poem_set = set(new_poem_clean.split())\n",
"\n",
"print(len(poem_set))\n",
"print(len(new_poem_set))\n",
"print(poem_set - new_poem_set)\n",
"print(new_poem_set - poem_set)\n",
"print(sorted(poem_set & new_poem_set))\n"
]
},
{
Expand All @@ -193,7 +381,7 @@
},
{
"cell_type": "code",
"execution_count": 51,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -202,11 +390,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 43,
"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"
"# Your code here\n",
"\n",
"grades[\"Bob\"][\"Philosophy\"] = 100\n",
"print(grades)"
]
},
{
Expand Down Expand Up @@ -239,14 +438,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"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",
"\n",
"# Your code here"
"# Your code here\n",
"\n",
"zipped = zip(keys, values)\n",
"print(list(zipped))"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}\n"
]
}
],
"source": [
"new_dict = dict (zip(keys, values))\n",
"print(new_dict)"
]
},
{
Expand Down Expand Up @@ -275,17 +503,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Chemistry\n"
]
}
],
"source": [
"# Your code here"
"# Your code here\n",
"min_score = min(new_dict, key=new_dict.get)\n",
"print(min_score)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -299,7 +537,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.14.2"
}
},
"nbformat": 4,
Expand Down