Skip to content

Commit f36d3ff

Browse files
committed
update
0 parents  commit f36d3ff

File tree

3 files changed

+350
-0
lines changed

3 files changed

+350
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"1. Write a Python function that takes a list of words and reytrns the length of the longest one"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 63,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"data": {
17+
"text/plain": [
18+
"(8, 'resberry')"
19+
]
20+
},
21+
"execution_count": 63,
22+
"metadata": {},
23+
"output_type": "execute_result"
24+
}
25+
],
26+
"source": [
27+
"list1 = ['apple', 'banana', 'resberry', 'avacado']\n",
28+
"def get_longest_word(word_list):\n",
29+
" max_len = 0\n",
30+
" for word in word_list:\n",
31+
" if len(word) > max_len:\n",
32+
" max_len = len(word)\n",
33+
" result = word\n",
34+
" return max_len, result\n",
35+
"\n",
36+
"get_longest_word(list1)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"scrolled": false
44+
},
45+
"outputs": [],
46+
"source": []
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"2. Write a Python program to count the number of characters in a string"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 68,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"data": {
62+
"text/plain": [
63+
"11"
64+
]
65+
},
66+
"execution_count": 68,
67+
"metadata": {},
68+
"output_type": "execute_result"
69+
}
70+
],
71+
"source": [
72+
"text = \"hello world\"\n",
73+
"def count_chars(txt):\n",
74+
" result = 0\n",
75+
" for char in txt:\n",
76+
" result += 1\n",
77+
" return result\n",
78+
"count_chars(text)"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 76,
84+
"metadata": {},
85+
"outputs": [
86+
{
87+
"data": {
88+
"text/plain": [
89+
"11"
90+
]
91+
},
92+
"execution_count": 76,
93+
"metadata": {},
94+
"output_type": "execute_result"
95+
}
96+
],
97+
"source": [
98+
"# second \n",
99+
"text = \"hello world\"\n",
100+
"def count_chars2(txt):\n",
101+
" return len(list(txt))\n",
102+
"count_chars2(text)"
103+
]
104+
},
105+
{
106+
"cell_type": "markdown",
107+
"metadata": {},
108+
"source": [
109+
"3. Write a Python program to sort (ascending and descending) a dictionary by value"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": 60,
115+
"metadata": {},
116+
"outputs": [
117+
{
118+
"name": "stdout",
119+
"output_type": "stream",
120+
"text": [
121+
"{'a': 1, 'b': 100, 'c': 77, 'd': 66, 'e': 55}\n"
122+
]
123+
}
124+
],
125+
"source": [
126+
"dict1 = {'a':1, 'b':100, 'c':77, 'd':66, 'e':55}\n",
127+
"print(dict1)\n"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"metadata": {},
134+
"outputs": [],
135+
"source": []
136+
}
137+
],
138+
"metadata": {
139+
"kernelspec": {
140+
"display_name": "Python 3",
141+
"language": "python",
142+
"name": "python3"
143+
},
144+
"language_info": {
145+
"codemirror_mode": {
146+
"name": "ipython",
147+
"version": 3
148+
},
149+
"file_extension": ".py",
150+
"mimetype": "text/x-python",
151+
"name": "python",
152+
"nbconvert_exporter": "python",
153+
"pygments_lexer": "ipython3",
154+
"version": "3.7.4"
155+
}
156+
},
157+
"nbformat": 4,
158+
"nbformat_minor": 2
159+
}

git

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
core.symlinks=false
2+
core.autocrlf=true
3+
color.diff=auto
4+
color.status=auto
5+
color.branch=auto
6+
color.interactive=true
7+
pack.packsizelimit=2g
8+
help.format=html
9+
http.sslcainfo=/ssl/certs/ca-bundle.crt
10+
diff.astextplain.textconv=astextplain
11+
rebase.autosquash=true
12+
filter.lfs.clean=git-lfs clean -- %f
13+
filter.lfs.smudge=git-lfs smudge --skip -- %f
14+
filter.lfs.process=git-lfs filter-process --skip
15+
filter.lfs.required=true
16+
user.name=lzhanggit
17+
18+
filter.lfs.smudge=git-lfs smudge -- %f
19+
filter.lfs.process=git-lfs filter-process
20+
filter.lfs.required=true
21+
filter.lfs.clean=git-lfs clean -- %f
22+
core.repositoryformatversion=0
23+
core.filemode=false
24+
core.bare=false
25+
core.logallrefupdates=true
26+
core.symlinks=false
27+
core.ignorecase=true
28+
remote.origin.url=https://github.com/lzhanggit/pythonlab.git
29+
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
30+
branch.master.remote=origin
31+
branch.master.merge=refs/heads/master
32+

week3.ipynb

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"1. Write a Python function that takes a list of words and reytrns the length of the longest one"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 63,
13+
"metadata": {},
14+
"outputs": [
15+
{
16+
"data": {
17+
"text/plain": [
18+
"(8, 'resberry')"
19+
]
20+
},
21+
"execution_count": 63,
22+
"metadata": {},
23+
"output_type": "execute_result"
24+
}
25+
],
26+
"source": [
27+
"list1 = ['apple', 'banana', 'resberry', 'avacado']\n",
28+
"def get_longest_word(word_list):\n",
29+
" max_len = 0\n",
30+
" for word in word_list:\n",
31+
" if len(word) > max_len:\n",
32+
" max_len = len(word)\n",
33+
" result = word\n",
34+
" return max_len, result\n",
35+
"\n",
36+
"get_longest_word(list1)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"scrolled": false
44+
},
45+
"outputs": [],
46+
"source": []
47+
},
48+
{
49+
"cell_type": "markdown",
50+
"metadata": {},
51+
"source": [
52+
"2. Write a Python program to count the number of characters in a string"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 68,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"data": {
62+
"text/plain": [
63+
"11"
64+
]
65+
},
66+
"execution_count": 68,
67+
"metadata": {},
68+
"output_type": "execute_result"
69+
}
70+
],
71+
"source": [
72+
"text = \"hello world\"\n",
73+
"def count_chars(txt):\n",
74+
" result = 0\n",
75+
" for char in txt:\n",
76+
" result += 1\n",
77+
" return result\n",
78+
"count_chars(text)"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 76,
84+
"metadata": {},
85+
"outputs": [
86+
{
87+
"data": {
88+
"text/plain": [
89+
"11"
90+
]
91+
},
92+
"execution_count": 76,
93+
"metadata": {},
94+
"output_type": "execute_result"
95+
}
96+
],
97+
"source": [
98+
"# second \n",
99+
"text = \"hello world\"\n",
100+
"def count_chars2(txt):\n",
101+
" return len(list(txt))\n",
102+
"count_chars2(text)"
103+
]
104+
},
105+
{
106+
"cell_type": "markdown",
107+
"metadata": {},
108+
"source": [
109+
"3. Write a Python program to sort (ascending and descending) a dictionary by value"
110+
]
111+
},
112+
{
113+
"cell_type": "code",
114+
"execution_count": 60,
115+
"metadata": {},
116+
"outputs": [
117+
{
118+
"name": "stdout",
119+
"output_type": "stream",
120+
"text": [
121+
"{'a': 1, 'b': 100, 'c': 77, 'd': 66, 'e': 55}\n"
122+
]
123+
}
124+
],
125+
"source": [
126+
"dict1 = {'a':1, 'b':100, 'c':77, 'd':66, 'e':55}\n",
127+
"print(dict1)\n"
128+
]
129+
},
130+
{
131+
"cell_type": "code",
132+
"execution_count": null,
133+
"metadata": {},
134+
"outputs": [],
135+
"source": []
136+
}
137+
],
138+
"metadata": {
139+
"kernelspec": {
140+
"display_name": "Python 3",
141+
"language": "python",
142+
"name": "python3"
143+
},
144+
"language_info": {
145+
"codemirror_mode": {
146+
"name": "ipython",
147+
"version": 3
148+
},
149+
"file_extension": ".py",
150+
"mimetype": "text/x-python",
151+
"name": "python",
152+
"nbconvert_exporter": "python",
153+
"pygments_lexer": "ipython3",
154+
"version": "3.7.4"
155+
}
156+
},
157+
"nbformat": 4,
158+
"nbformat_minor": 2
159+
}

0 commit comments

Comments
 (0)