Skip to content

Commit 6ffec4e

Browse files
committed
Day 2 and Day 3 changes
1 parent e0caa5a commit 6ffec4e

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed

python_concepts/dictionary.ipynb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,35 @@
9494
"# convert dictionary keys into a list using keys() method\n",
9595
"list(dict1.keys())"
9696
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": 11,
101+
"metadata": {},
102+
"outputs": [
103+
{
104+
"name": "stdout",
105+
"output_type": "stream",
106+
"text": [
107+
"a 1\n",
108+
"{'A': 100, 'B': 200, 'C': 300}\n"
109+
]
110+
}
111+
],
112+
"source": [
113+
"### Dictionary comprehension works similar to list comprehension. Below we will use dict comprehension to convert\n",
114+
"### dictionary from one form to another.\n",
115+
"### dict.items() return key value pair\n",
116+
"\n",
117+
"dict1 = {'a': 1}\n",
118+
"type(dict1.items())\n",
119+
"for k, v in dict1.items():\n",
120+
" print(k, v)\n",
121+
" \n",
122+
"dict1 = {'a': 1, 'b': 2, 'c': 3}\n",
123+
"dict2 = {k.upper():v*100 for (k,v) in dict1.items()}\n",
124+
"print(dict2)\n"
125+
]
97126
}
98127
],
99128
"metadata": {

python_concepts/itertools.ipynb

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Itertools"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"#### In this notebook we learn all the concepts and use cases of itertools library"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 1,
20+
"metadata": {},
21+
"outputs": [
22+
{
23+
"name": "stdout",
24+
"output_type": "stream",
25+
"text": [
26+
"atif\n",
27+
"amit\n",
28+
"Naoto\n",
29+
"Arti\n",
30+
"zoheb\n",
31+
"kasif\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"## Itertools.chain can be used to combine elements of different data structure\n",
37+
"\n",
38+
"import itertools\n",
39+
"group_list = ['atif', 'amit']\n",
40+
"group_set = {'Naoto', 'Arti', 'Arti'}\n",
41+
"group_tuple = ('zoheb', 'kasif')\n",
42+
"for colleagues in itertools.chain(group_list, group_set, group_tuple):\n",
43+
" print(colleagues)\n"
44+
]
45+
}
46+
],
47+
"metadata": {
48+
"kernelspec": {
49+
"display_name": "dashboard",
50+
"language": "python",
51+
"name": "python3"
52+
},
53+
"language_info": {
54+
"codemirror_mode": {
55+
"name": "ipython",
56+
"version": 3
57+
},
58+
"file_extension": ".py",
59+
"mimetype": "text/x-python",
60+
"name": "python",
61+
"nbconvert_exporter": "python",
62+
"pygments_lexer": "ipython3",
63+
"version": "3.10.6"
64+
}
65+
},
66+
"nbformat": 4,
67+
"nbformat_minor": 2
68+
}

python_daily_exercies/day1_25_12_2023.ipynb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@
117117
"for i , j in zip(numbers[::2], numbers[1::2]):\n",
118118
" print(i, j)"
119119
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 11,
124+
"metadata": {},
125+
"outputs": [
126+
{
127+
"name": "stdout",
128+
"output_type": "stream",
129+
"text": [
130+
"False\n"
131+
]
132+
}
133+
],
134+
"source": [
135+
"dict1 = {'a':2, 'b':4 , 'c':6, 'd':8 , 'e':10}\n",
136+
"\n",
137+
"print('g' in dict1)"
138+
]
120139
}
121140
],
122141
"metadata": {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Day 2\n",
8+
"#### We will practice list slicing and take up the question from Coding Computing Coach email\n",
9+
"#### Question: Suppose you have a list of numbers from 1 to 31, representing the dates in a month.\n",
10+
"#### Given that the first Sunday occurs on the 3rd, can you slice out all dates that would be Sundays?"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 3,
16+
"metadata": {},
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"[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"
23+
]
24+
},
25+
{
26+
"data": {
27+
"text/plain": [
28+
"[3, 10, 17, 24, 31]"
29+
]
30+
},
31+
"execution_count": 3,
32+
"metadata": {},
33+
"output_type": "execute_result"
34+
}
35+
],
36+
"source": [
37+
"calender = [i for i in range(1,32)]\n",
38+
"print(calender)\n",
39+
"sundays = calender[2::7]\n",
40+
"sundays"
41+
]
42+
}
43+
],
44+
"metadata": {
45+
"kernelspec": {
46+
"display_name": "dashboard",
47+
"language": "python",
48+
"name": "python3"
49+
},
50+
"language_info": {
51+
"codemirror_mode": {
52+
"name": "ipython",
53+
"version": 3
54+
},
55+
"file_extension": ".py",
56+
"mimetype": "text/x-python",
57+
"name": "python",
58+
"nbconvert_exporter": "python",
59+
"pygments_lexer": "ipython3",
60+
"version": "3.10.6"
61+
}
62+
},
63+
"nbformat": 4,
64+
"nbformat_minor": 2
65+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### Day 3"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"##### We have dictionary composed of {'a':1, 'b':2, 'c':3} and we have to convert into {'A':100, 'B':200, 'C':300}"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": null,
20+
"metadata": {
21+
"vscode": {
22+
"languageId": "plaintext"
23+
}
24+
},
25+
"outputs": [],
26+
"source": [
27+
"dict1 = {'a': 1, 'b': 2, 'c': 3}\n",
28+
"dict2 = {k.upper():v*100 for (k,v) in dict1.items()}\n",
29+
"# Here dictionary.items returns key value pair\n",
30+
"print(dict2)"
31+
]
32+
}
33+
],
34+
"metadata": {
35+
"language_info": {
36+
"name": "python"
37+
}
38+
},
39+
"nbformat": 4,
40+
"nbformat_minor": 2
41+
}

0 commit comments

Comments
 (0)