Skip to content

Commit 2caf955

Browse files
committed
Day 2
1 parent ad85916 commit 2caf955

File tree

6 files changed

+498
-0
lines changed

6 files changed

+498
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# import the module \n",
10+
"import re\n",
11+
"my_regex = re.compile(\"[0-9]+\",re.I)"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 2,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# use an alias\n",
21+
"import re as regex\n",
22+
"my_regex = regex.compile(\"[0-9]+\",regex.I)"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 9,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"import matplotlib.pyplot as plt"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 10,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"#import specific modules explicitly\n",
41+
"from collections import defaultdict, Counter\n",
42+
"lookup = defaultdict(int)\n",
43+
"my_counter = Counter()"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 12,
49+
"metadata": {},
50+
"outputs": [
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"2.5\n"
56+
]
57+
}
58+
],
59+
"source": [
60+
"#Python 2.7 uses integer division by default\n",
61+
"from __future__ import division\n",
62+
"print 5/2"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 13,
68+
"metadata": {},
69+
"outputs": [
70+
{
71+
"name": "stdout",
72+
"output_type": "stream",
73+
"text": [
74+
"2\n"
75+
]
76+
}
77+
],
78+
"source": [
79+
"print 5//2"
80+
]
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 2",
86+
"language": "python",
87+
"name": "python2"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 2
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython2",
99+
"version": "2.7.18"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 2
104+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"data": {
10+
"text/plain": [
11+
"u'C:\\\\Users\\\\tanshah'"
12+
]
13+
},
14+
"execution_count": 1,
15+
"metadata": {},
16+
"output_type": "execute_result"
17+
}
18+
],
19+
"source": [
20+
"pwd"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"metadata": {},
27+
"outputs": [],
28+
"source": [
29+
"#python uses indentation\n",
30+
"for i in [1,2,3,4,5]\n",
31+
" "
32+
]
33+
}
34+
],
35+
"metadata": {
36+
"kernelspec": {
37+
"display_name": "Python 2",
38+
"language": "python",
39+
"name": "python2"
40+
},
41+
"language_info": {
42+
"codemirror_mode": {
43+
"name": "ipython",
44+
"version": 2
45+
},
46+
"file_extension": ".py",
47+
"mimetype": "text/x-python",
48+
"name": "python",
49+
"nbconvert_exporter": "python",
50+
"pygments_lexer": "ipython2",
51+
"version": "2.7.18"
52+
}
53+
},
54+
"nbformat": 4,
55+
"nbformat_minor": 2
56+
}

Functions.ipynb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"#function is a rule for taking zero or more inputs and returning a corresponding output\n",
10+
"\n",
11+
"def double(x):\n",
12+
" \"\"\"Enter an optional docstring that explains what function does.\n",
13+
" This function multiplies its input by 2\"\"\"\n",
14+
" return x*2"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 6,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"# we can assign fucntions to variables and pass them into functions just like any other arguments:\n",
24+
"\n",
25+
"def apply_to_one(f):\n",
26+
" \"\"\"Calls function f with its argument 1\"\"\"\n",
27+
" return f(1)"
28+
]
29+
},
30+
{
31+
"cell_type": "code",
32+
"execution_count": 7,
33+
"metadata": {},
34+
"outputs": [
35+
{
36+
"name": "stdout",
37+
"output_type": "stream",
38+
"text": [
39+
"2\n"
40+
]
41+
}
42+
],
43+
"source": [
44+
"my_double = double\n",
45+
"x = apply_to_one(my_double)\n",
46+
"print x"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": 8,
52+
"metadata": {},
53+
"outputs": [
54+
{
55+
"name": "stdout",
56+
"output_type": "stream",
57+
"text": [
58+
"5\n"
59+
]
60+
}
61+
],
62+
"source": [
63+
"#can be used to create anonymous functions or lambdas\n",
64+
"y = apply_to_one(lambda x: x+4)\n",
65+
"print y"
66+
]
67+
}
68+
],
69+
"metadata": {
70+
"kernelspec": {
71+
"display_name": "Python 2",
72+
"language": "python",
73+
"name": "python2"
74+
},
75+
"language_info": {
76+
"codemirror_mode": {
77+
"name": "ipython",
78+
"version": 2
79+
},
80+
"file_extension": ".py",
81+
"mimetype": "text/x-python",
82+
"name": "python",
83+
"nbconvert_exporter": "python",
84+
"pygments_lexer": "ipython2",
85+
"version": "2.7.18"
86+
}
87+
},
88+
"nbformat": 4,
89+
"nbformat_minor": 2
90+
}

Modules.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# import the module \n",
10+
"import re\n",
11+
"my_regex = re.compile(\"[0-9]+\",re.I)"
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": 2,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"# use an alias\n",
21+
"import re as regex\n",
22+
"my_regex = regex.compile(\"[0-9]+\",regex.I)"
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 9,
28+
"metadata": {},
29+
"outputs": [],
30+
"source": [
31+
"import matplotlib.pyplot as plt"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 10,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"#import specific modules explicitly\n",
41+
"from collections import defaultdict, Counter\n",
42+
"lookup = defaultdict(int)\n",
43+
"my_counter = Counter()"
44+
]
45+
},
46+
{
47+
"cell_type": "code",
48+
"execution_count": 12,
49+
"metadata": {},
50+
"outputs": [
51+
{
52+
"name": "stdout",
53+
"output_type": "stream",
54+
"text": [
55+
"2.5\n"
56+
]
57+
}
58+
],
59+
"source": [
60+
"#Python 2.7 uses integer division by default\n",
61+
"from __future__ import division\n",
62+
"print 5/2"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 13,
68+
"metadata": {},
69+
"outputs": [
70+
{
71+
"name": "stdout",
72+
"output_type": "stream",
73+
"text": [
74+
"2\n"
75+
]
76+
}
77+
],
78+
"source": [
79+
"print 5//2"
80+
]
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 2",
86+
"language": "python",
87+
"name": "python2"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 2
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython2",
99+
"version": "2.7.18"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 2
104+
}

0 commit comments

Comments
 (0)