Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
PAlena authored Oct 29, 2023
1 parent 67dd1ec commit 0ac5c1c
Showing 1 changed file with 263 additions and 0 deletions.
263 changes: 263 additions & 0 deletions seminar_2_empty.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "81a927b5",
"metadata": {},
"source": [
"# Seminar: Lists, dictionaries, functions, exceptions\n"
]
},
{
"cell_type": "markdown",
"id": "7917a993",
"metadata": {},
"source": [
"### Task 1. \n",
"\n",
"Write a function which will sum up all values in the list"
]
},
{
"cell_type": "markdown",
"id": "1401ca62",
"metadata": {},
"source": [
"#### a. For the case when input is list of integers."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8750cd32",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "e06770f1",
"metadata": {},
"source": [
"#### b. What will be if the input is list of strings?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c4aa17cc",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "d67d8c92",
"metadata": {},
"source": [
"#### c. Rewrite the function in the way that we will get a message 'can not work with not numerical types' if list contains not numerical elements."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d95e80d8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3240b759",
"metadata": {},
"source": [
"#### d. Why do we need to write the exceptions?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ad2390cf",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "278db275",
"metadata": {},
"source": [
"### Task 2."
]
},
{
"cell_type": "markdown",
"id": "d3d3a943",
"metadata": {},
"source": [
"In this task we will work with the dictionary which is the plan for the grocery store:"
]
},
{
"cell_type": "code",
"execution_count": 161,
"id": "eba4a98b",
"metadata": {},
"outputs": [],
"source": [
"dic_food = {'apple':5, 'orange':4, 'onion':9}"
]
},
{
"cell_type": "markdown",
"id": "3074601e",
"metadata": {},
"source": [
"#### a. Calculate how many products in total do we have. How many fruits?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d13457fd",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "a3ca5ec2",
"metadata": {},
"source": [
"#### b. Add one more apple and change the numbers of onions to 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d85c63a1",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "7c03197c",
"metadata": {},
"source": [
"#### c. Make the same dictionary from the lists: "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "167aca00",
"metadata": {},
"outputs": [],
"source": [
"prod_name = ['apple', 'orange', 'onion']\n",
"prod_amount = [1,5,5]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "31f17c02",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "3649c1cb",
"metadata": {},
"source": [
"#### d. What will happened if we have dublicates in the list of keys?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c66a0a13",
"metadata": {},
"outputs": [],
"source": [
"prod_name = ['apple', 'orange', 'onion', 'apple']\n",
"prod_amount = [1,5,3,5]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0c5aec52",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "873a48f6",
"metadata": {},
"source": [
"### Task 3 (from HW) leetcode 219. Contains Duplicate II\n",
"https://leetcode.com/problems/contains-duplicate-ii/\n",
"\n",
"Given an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that \n",
"\n",
"nums[ i ] == nums[ j ] and abs(i - j) <= k."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e168222a",
"metadata": {},
"outputs": [],
"source": [
"def containsNearbyDuplicate(self, nums, k):\n",
" \"\"\"\n",
" :type nums: List[int]\n",
" :type k: int\n",
" :rtype: bool\n",
" \"\"\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae231b73",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "689d6ae1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 0ac5c1c

Please sign in to comment.