Skip to content

Commit b8ecdd7

Browse files
committed
python-practice
1 parent 109ef26 commit b8ecdd7

2 files changed

Lines changed: 330 additions & 0 deletions

File tree

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"#### 题目描述\n",
8+
"实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。\n",
9+
"\n",
10+
"示例 1:\n",
11+
"\n",
12+
"输入: \"Hello\"\n",
13+
"\n",
14+
"输出: \"hello\"\n",
15+
"\n",
16+
"#### 思路\n",
17+
"1. 直接使用内置函数\n",
18+
"2. 使用字典"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 4,
24+
"metadata": {
25+
"ExecuteTime": {
26+
"end_time": "2019-07-01T07:13:18.693798Z",
27+
"start_time": "2019-07-01T07:13:18.683899Z"
28+
}
29+
},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"'hello'"
35+
]
36+
},
37+
"execution_count": 4,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"class Solution(object):\n",
44+
" def toLowerCase(self, str):\n",
45+
" \"\"\"\n",
46+
" :type str: str\n",
47+
" :rtype: str\n",
48+
" \"\"\"\n",
49+
" return str.lower()\n",
50+
" \n",
51+
" \n",
52+
"str = \"Hello\"\n",
53+
"solution = Solution()\n",
54+
"solution.toLowerCase(str)"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 29,
60+
"metadata": {
61+
"ExecuteTime": {
62+
"end_time": "2019-07-02T00:57:54.821736Z",
63+
"start_time": "2019-07-02T00:57:54.805132Z"
64+
}
65+
},
66+
"outputs": [
67+
{
68+
"data": {
69+
"text/plain": [
70+
"'hello'"
71+
]
72+
},
73+
"execution_count": 29,
74+
"metadata": {},
75+
"output_type": "execute_result"
76+
}
77+
],
78+
"source": [
79+
"class Solution(object):\n",
80+
" def toLowerCase(self, str):\n",
81+
" \"\"\"\n",
82+
" :type str: str\n",
83+
" :rtype: str\n",
84+
" \"\"\"\n",
85+
" letters = {\n",
86+
" 'A': 'a',\n",
87+
" 'B': 'b',\n",
88+
" 'C': 'c',\n",
89+
" 'D': 'd',\n",
90+
" 'E': 'e',\n",
91+
" 'F': 'f',\n",
92+
" 'G': 'g',\n",
93+
" 'H': 'h',\n",
94+
" 'I': 'i',\n",
95+
" 'J': 'j',\n",
96+
" 'K': 'k',\n",
97+
" 'L': 'l',\n",
98+
" 'M': 'm',\n",
99+
" 'N': 'n',\n",
100+
" 'O': 'o',\n",
101+
" 'P': 'p',\n",
102+
" 'Q': 'q',\n",
103+
" 'R': 'r',\n",
104+
" 'S': 's',\n",
105+
" 'T': 't',\n",
106+
" 'U': 'u',\n",
107+
" 'V': 'v',\n",
108+
" 'W': 'w',\n",
109+
" 'X': 'x',\n",
110+
" 'Y': 'y',\n",
111+
" 'Z': 'z'\n",
112+
" }\n",
113+
" for ele in str:\n",
114+
" if ele in letters:\n",
115+
" str = str.replace(ele, letters[ele])\n",
116+
" return str\n",
117+
" \n",
118+
"str = \"Hello\"\n",
119+
"solution = Solution()\n",
120+
"solution.toLowerCase(str)"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": null,
126+
"metadata": {},
127+
"outputs": [],
128+
"source": []
129+
}
130+
],
131+
"metadata": {
132+
"kernelspec": {
133+
"display_name": "python pratice",
134+
"language": "python",
135+
"name": "env_name"
136+
},
137+
"language_info": {
138+
"codemirror_mode": {
139+
"name": "ipython",
140+
"version": 3
141+
},
142+
"file_extension": ".py",
143+
"mimetype": "text/x-python",
144+
"name": "python",
145+
"nbconvert_exporter": "python",
146+
"pygments_lexer": "ipython3",
147+
"version": "3.7.1"
148+
},
149+
"toc": {
150+
"base_numbering": 1,
151+
"nav_menu": {},
152+
"number_sections": true,
153+
"sideBar": true,
154+
"skip_h1_title": false,
155+
"title_cell": "Table of Contents",
156+
"title_sidebar": "Contents",
157+
"toc_cell": false,
158+
"toc_position": {},
159+
"toc_section_display": true,
160+
"toc_window_display": false
161+
}
162+
},
163+
"nbformat": 4,
164+
"nbformat_minor": 2
165+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"#### 题目描述\n",
8+
"实现函数 ToLowerCase(),该函数接收一个字符串参数 str,并将该字符串中的大写字母转换成小写字母,之后返回新的字符串。\n",
9+
"\n",
10+
"示例 1:\n",
11+
"\n",
12+
"输入: \"Hello\"\n",
13+
"\n",
14+
"输出: \"hello\"\n",
15+
"\n",
16+
"#### 思路\n",
17+
"1. 直接使用内置函数\n",
18+
"2. 使用字典"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 4,
24+
"metadata": {
25+
"ExecuteTime": {
26+
"end_time": "2019-07-01T07:13:18.693798Z",
27+
"start_time": "2019-07-01T07:13:18.683899Z"
28+
}
29+
},
30+
"outputs": [
31+
{
32+
"data": {
33+
"text/plain": [
34+
"'hello'"
35+
]
36+
},
37+
"execution_count": 4,
38+
"metadata": {},
39+
"output_type": "execute_result"
40+
}
41+
],
42+
"source": [
43+
"class Solution(object):\n",
44+
" def toLowerCase(self, str):\n",
45+
" \"\"\"\n",
46+
" :type str: str\n",
47+
" :rtype: str\n",
48+
" \"\"\"\n",
49+
" return str.lower()\n",
50+
" \n",
51+
" \n",
52+
"str = \"Hello\"\n",
53+
"solution = Solution()\n",
54+
"solution.toLowerCase(str)"
55+
]
56+
},
57+
{
58+
"cell_type": "code",
59+
"execution_count": 29,
60+
"metadata": {
61+
"ExecuteTime": {
62+
"end_time": "2019-07-02T00:57:54.821736Z",
63+
"start_time": "2019-07-02T00:57:54.805132Z"
64+
}
65+
},
66+
"outputs": [
67+
{
68+
"data": {
69+
"text/plain": [
70+
"'hello'"
71+
]
72+
},
73+
"execution_count": 29,
74+
"metadata": {},
75+
"output_type": "execute_result"
76+
}
77+
],
78+
"source": [
79+
"class Solution(object):\n",
80+
" def toLowerCase(self, str):\n",
81+
" \"\"\"\n",
82+
" :type str: str\n",
83+
" :rtype: str\n",
84+
" \"\"\"\n",
85+
" letters = {\n",
86+
" 'A': 'a',\n",
87+
" 'B': 'b',\n",
88+
" 'C': 'c',\n",
89+
" 'D': 'd',\n",
90+
" 'E': 'e',\n",
91+
" 'F': 'f',\n",
92+
" 'G': 'g',\n",
93+
" 'H': 'h',\n",
94+
" 'I': 'i',\n",
95+
" 'J': 'j',\n",
96+
" 'K': 'k',\n",
97+
" 'L': 'l',\n",
98+
" 'M': 'm',\n",
99+
" 'N': 'n',\n",
100+
" 'O': 'o',\n",
101+
" 'P': 'p',\n",
102+
" 'Q': 'q',\n",
103+
" 'R': 'r',\n",
104+
" 'S': 's',\n",
105+
" 'T': 't',\n",
106+
" 'U': 'u',\n",
107+
" 'V': 'v',\n",
108+
" 'W': 'w',\n",
109+
" 'X': 'x',\n",
110+
" 'Y': 'y',\n",
111+
" 'Z': 'z'\n",
112+
" }\n",
113+
" for ele in str:\n",
114+
" if ele in letters:\n",
115+
" str = str.replace(ele, letters[ele])\n",
116+
" return str\n",
117+
" \n",
118+
"str = \"Hello\"\n",
119+
"solution = Solution()\n",
120+
"solution.toLowerCase(str)"
121+
]
122+
},
123+
{
124+
"cell_type": "code",
125+
"execution_count": null,
126+
"metadata": {},
127+
"outputs": [],
128+
"source": []
129+
}
130+
],
131+
"metadata": {
132+
"kernelspec": {
133+
"display_name": "python pratice",
134+
"language": "python",
135+
"name": "env_name"
136+
},
137+
"language_info": {
138+
"codemirror_mode": {
139+
"name": "ipython",
140+
"version": 3
141+
},
142+
"file_extension": ".py",
143+
"mimetype": "text/x-python",
144+
"name": "python",
145+
"nbconvert_exporter": "python",
146+
"pygments_lexer": "ipython3",
147+
"version": "3.7.1"
148+
},
149+
"toc": {
150+
"base_numbering": 1,
151+
"nav_menu": {},
152+
"number_sections": true,
153+
"sideBar": true,
154+
"skip_h1_title": false,
155+
"title_cell": "Table of Contents",
156+
"title_sidebar": "Contents",
157+
"toc_cell": false,
158+
"toc_position": {},
159+
"toc_section_display": true,
160+
"toc_window_display": false
161+
}
162+
},
163+
"nbformat": 4,
164+
"nbformat_minor": 2
165+
}

0 commit comments

Comments
 (0)