Skip to content

Commit 93d61b4

Browse files
committed
u18
1 parent e41b783 commit 93d61b4

File tree

2 files changed

+98
-2
lines changed

2 files changed

+98
-2
lines changed

.ipynb_checkpoints/Decorators-checkpoint.ipynb

+49-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,55 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"#Decorators"
7+
"#Decorators\n",
8+
"Before getting started with Decorators, a quick reminder from the Lecture on Nested Statements and Scopes, functions are objects and can be assigned labels.Lets look a t quick example of assigning a label to a function in order to pass it into another function:"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 3,
14+
"metadata": {
15+
"collapsed": false
16+
},
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"3\n"
23+
]
24+
}
25+
],
26+
"source": [
27+
"def is_even(num):\n",
28+
" \"\"\"Return True if number is even.\"\"\"\n",
29+
" return (num % 2) == 0\n",
30+
"\n",
31+
"def count_occurrences(input_list, func):\n",
32+
" \"\"\"Return the number of times func returns Ture for a list\"\"\" \n",
33+
" return sum([1 for item in input_list if func(item)])\n",
34+
"\n",
35+
"func = is_even\n",
36+
"lst = [1,2,3,4,5,6]\n",
37+
"\n",
38+
"print count_occurrences(lst, func)"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {
45+
"collapsed": true
46+
},
47+
"outputs": [],
48+
"source": []
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"https://www.jeffknupp.com/blog/2013/11/29/improve-your-python-decorators-explained/\n",
55+
"http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/"
856
]
957
},
1058
{

Decorators.ipynb

+49-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,55 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"#Decorators"
7+
"#Decorators\n",
8+
"Before getting started with Decorators, a quick reminder from the Lecture on Nested Statements and Scopes, functions are objects and can be assigned labels.Lets look a t quick example of assigning a label to a function in order to pass it into another function:"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 3,
14+
"metadata": {
15+
"collapsed": false
16+
},
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"3\n"
23+
]
24+
}
25+
],
26+
"source": [
27+
"def is_even(num):\n",
28+
" \"\"\"Return True if number is even.\"\"\"\n",
29+
" return (num % 2) == 0\n",
30+
"\n",
31+
"def count_occurrences(input_list, func):\n",
32+
" \"\"\"Return the number of times func returns Ture for a list\"\"\" \n",
33+
" return sum([1 for item in input_list if func(item)])\n",
34+
"\n",
35+
"func = is_even\n",
36+
"lst = [1,2,3,4,5,6]\n",
37+
"\n",
38+
"print count_occurrences(lst, func)"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {
45+
"collapsed": true
46+
},
47+
"outputs": [],
48+
"source": []
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"metadata": {},
53+
"source": [
54+
"https://www.jeffknupp.com/blog/2013/11/29/improve-your-python-decorators-explained/\n",
55+
"http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/"
856
]
957
},
1058
{

0 commit comments

Comments
 (0)