Skip to content

Commit

Permalink
Day 2 and Day 3 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
atifiu committed Dec 31, 2023
1 parent e0caa5a commit 6ffec4e
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 0 deletions.
29 changes: 29 additions & 0 deletions python_concepts/dictionary.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,35 @@
"# convert dictionary keys into a list using keys() method\n",
"list(dict1.keys())"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a 1\n",
"{'A': 100, 'B': 200, 'C': 300}\n"
]
}
],
"source": [
"### Dictionary comprehension works similar to list comprehension. Below we will use dict comprehension to convert\n",
"### dictionary from one form to another.\n",
"### dict.items() return key value pair\n",
"\n",
"dict1 = {'a': 1}\n",
"type(dict1.items())\n",
"for k, v in dict1.items():\n",
" print(k, v)\n",
" \n",
"dict1 = {'a': 1, 'b': 2, 'c': 3}\n",
"dict2 = {k.upper():v*100 for (k,v) in dict1.items()}\n",
"print(dict2)\n"
]
}
],
"metadata": {
Expand Down
68 changes: 68 additions & 0 deletions python_concepts/itertools.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Itertools"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### In this notebook we learn all the concepts and use cases of itertools library"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"atif\n",
"amit\n",
"Naoto\n",
"Arti\n",
"zoheb\n",
"kasif\n"
]
}
],
"source": [
"## Itertools.chain can be used to combine elements of different data structure\n",
"\n",
"import itertools\n",
"group_list = ['atif', 'amit']\n",
"group_set = {'Naoto', 'Arti', 'Arti'}\n",
"group_tuple = ('zoheb', 'kasif')\n",
"for colleagues in itertools.chain(group_list, group_set, group_tuple):\n",
" print(colleagues)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dashboard",
"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.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
19 changes: 19 additions & 0 deletions python_daily_exercies/day1_25_12_2023.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@
"for i , j in zip(numbers[::2], numbers[1::2]):\n",
" print(i, j)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"dict1 = {'a':2, 'b':4 , 'c':6, 'd':8 , 'e':10}\n",
"\n",
"print('g' in dict1)"
]
}
],
"metadata": {
Expand Down
65 changes: 65 additions & 0 deletions python_daily_exercies/day2_30_12_2023.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Day 2\n",
"#### We will practice list slicing and take up the question from Coding Computing Coach email\n",
"#### Question: Suppose you have a list of numbers from 1 to 31, representing the dates in a month.\n",
"#### Given that the first Sunday occurs on the 3rd, can you slice out all dates that would be Sundays?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]\n"
]
},
{
"data": {
"text/plain": [
"[3, 10, 17, 24, 31]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"calender = [i for i in range(1,32)]\n",
"print(calender)\n",
"sundays = calender[2::7]\n",
"sundays"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "dashboard",
"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.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
41 changes: 41 additions & 0 deletions python_daily_exercies/day3_31_12_2023.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Day 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### We have dictionary composed of {'a':1, 'b':2, 'c':3} and we have to convert into {'A':100, 'B':200, 'C':300}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": [
"dict1 = {'a': 1, 'b': 2, 'c': 3}\n",
"dict2 = {k.upper():v*100 for (k,v) in dict1.items()}\n",
"# Here dictionary.items returns key value pair\n",
"print(dict2)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 6ffec4e

Please sign in to comment.