Skip to content

Commit 19e5220

Browse files
author
mohyeah
committed
25/2/1 learning~
1 parent 723048b commit 19e5220

2 files changed

Lines changed: 353 additions & 0 deletions

File tree

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {},
5+
"cell_type": "markdown",
6+
"source": "collections:https://zhuanlan.zhihu.com/p/343747724https://zhuanlan.zhihu.com/p/343747724",
7+
"id": "7e4c693555b9a69d"
8+
},
9+
{
10+
"metadata": {
11+
"ExecuteTime": {
12+
"end_time": "2025-02-01T12:07:30.259576Z",
13+
"start_time": "2025-02-01T12:07:30.242887Z"
14+
}
15+
},
16+
"cell_type": "code",
17+
"source": [
18+
"import collections\n",
19+
"from idlelib.colorizer import prog_group_name_to_tag"
20+
],
21+
"id": "6e3f51123be0ee05",
22+
"outputs": [],
23+
"execution_count": 2
24+
},
25+
{
26+
"metadata": {
27+
"ExecuteTime": {
28+
"end_time": "2025-02-01T12:10:19.799763Z",
29+
"start_time": "2025-02-01T12:10:19.788709Z"
30+
}
31+
},
32+
"cell_type": "code",
33+
"source": [
34+
"# 双向队列\n",
35+
"from _collections import deque\n",
36+
"# 右添加\n",
37+
"dq = deque('ghi')\n",
38+
"dq.append('j')\n",
39+
"dq"
40+
],
41+
"id": "d5ab8c55fa11eb7f",
42+
"outputs": [
43+
{
44+
"data": {
45+
"text/plain": [
46+
"deque(['g', 'h', 'i', 'j'])"
47+
]
48+
},
49+
"execution_count": 7,
50+
"metadata": {},
51+
"output_type": "execute_result"
52+
}
53+
],
54+
"execution_count": 7
55+
},
56+
{
57+
"metadata": {
58+
"ExecuteTime": {
59+
"end_time": "2025-02-01T12:08:50.982810Z",
60+
"start_time": "2025-02-01T12:08:50.969678Z"
61+
}
62+
},
63+
"cell_type": "code",
64+
"source": [
65+
"# 左添加\n",
66+
"dq.appendleft('f')\n",
67+
"dq"
68+
],
69+
"id": "3d4b805b770d0c13",
70+
"outputs": [
71+
{
72+
"data": {
73+
"text/plain": [
74+
"deque(['f', 'g', 'h', 'i', 'j'])"
75+
]
76+
},
77+
"execution_count": 4,
78+
"metadata": {},
79+
"output_type": "execute_result"
80+
}
81+
],
82+
"execution_count": 4
83+
},
84+
{
85+
"metadata": {
86+
"ExecuteTime": {
87+
"end_time": "2025-02-01T12:10:22.527589Z",
88+
"start_time": "2025-02-01T12:10:22.513576Z"
89+
}
90+
},
91+
"cell_type": "code",
92+
"source": [
93+
"# 右删除\n",
94+
"dq.pop()\n",
95+
"# 左删除\n",
96+
"dq.popleft()\n",
97+
"# 清空\n",
98+
"dq.clear()\n",
99+
"dq"
100+
],
101+
"id": "f8e7c985eca1614a",
102+
"outputs": [
103+
{
104+
"data": {
105+
"text/plain": [
106+
"deque([])"
107+
]
108+
},
109+
"execution_count": 8,
110+
"metadata": {},
111+
"output_type": "execute_result"
112+
}
113+
],
114+
"execution_count": 8
115+
},
116+
{
117+
"metadata": {
118+
"ExecuteTime": {
119+
"end_time": "2025-02-01T12:11:21.874989Z",
120+
"start_time": "2025-02-01T12:11:21.867705Z"
121+
}
122+
},
123+
"cell_type": "code",
124+
"source": [
125+
"# 浅拷贝\n",
126+
"dq = deque('hello, collections')\n",
127+
"y = dq.copy()\n",
128+
"y"
129+
],
130+
"id": "a93112183c256e5d",
131+
"outputs": [
132+
{
133+
"data": {
134+
"text/plain": [
135+
"deque(['h',\n",
136+
" 'e',\n",
137+
" 'l',\n",
138+
" 'l',\n",
139+
" 'o',\n",
140+
" ',',\n",
141+
" ' ',\n",
142+
" 'c',\n",
143+
" 'o',\n",
144+
" 'l',\n",
145+
" 'l',\n",
146+
" 'e',\n",
147+
" 'c',\n",
148+
" 't',\n",
149+
" 'i',\n",
150+
" 'o',\n",
151+
" 'n',\n",
152+
" 's'])"
153+
]
154+
},
155+
"execution_count": 9,
156+
"metadata": {},
157+
"output_type": "execute_result"
158+
}
159+
],
160+
"execution_count": 9
161+
},
162+
{
163+
"metadata": {
164+
"ExecuteTime": {
165+
"end_time": "2025-02-01T12:14:32.846825Z",
166+
"start_time": "2025-02-01T12:14:32.839953Z"
167+
}
168+
},
169+
"cell_type": "code",
170+
"source": [
171+
"# count\n",
172+
"dq.count('l')"
173+
],
174+
"id": "519d3b9ce2f01407",
175+
"outputs": [
176+
{
177+
"data": {
178+
"text/plain": [
179+
"4"
180+
]
181+
},
182+
"execution_count": 10,
183+
"metadata": {},
184+
"output_type": "execute_result"
185+
}
186+
],
187+
"execution_count": 10
188+
},
189+
{
190+
"metadata": {
191+
"ExecuteTime": {
192+
"end_time": "2025-02-01T12:16:09.418422Z",
193+
"start_time": "2025-02-01T12:16:09.408756Z"
194+
}
195+
},
196+
"cell_type": "code",
197+
"source": [
198+
"# extend, extendleft\n",
199+
"dq1 = deque('abc')\n",
200+
"dq2 = deque('def')\n",
201+
"dq1.extend(dq2)\n",
202+
"dq1\n",
203+
"\n",
204+
"# 与append区别\n",
205+
"dq1.append(dq2)\n",
206+
"dq1"
207+
],
208+
"id": "f019d1806cd64a60",
209+
"outputs": [
210+
{
211+
"data": {
212+
"text/plain": [
213+
"deque(['a', 'b', 'c', 'd', 'e', 'f', deque(['d', 'e', 'f'])])"
214+
]
215+
},
216+
"execution_count": 13,
217+
"metadata": {},
218+
"output_type": "execute_result"
219+
}
220+
],
221+
"execution_count": 13
222+
},
223+
{
224+
"metadata": {
225+
"ExecuteTime": {
226+
"end_time": "2025-02-01T12:17:10.039369Z",
227+
"start_time": "2025-02-01T12:17:10.023805Z"
228+
}
229+
},
230+
"cell_type": "code",
231+
"source": [
232+
"#index\n",
233+
"dq.index('s')"
234+
],
235+
"id": "76e2dd55b942fed5",
236+
"outputs": [
237+
{
238+
"data": {
239+
"text/plain": [
240+
"17"
241+
]
242+
},
243+
"execution_count": 16,
244+
"metadata": {},
245+
"output_type": "execute_result"
246+
}
247+
],
248+
"execution_count": 16
249+
},
250+
{
251+
"metadata": {
252+
"ExecuteTime": {
253+
"end_time": "2025-02-01T12:18:21.820420Z",
254+
"start_time": "2025-02-01T12:18:21.814911Z"
255+
}
256+
},
257+
"cell_type": "code",
258+
"source": "# remove(val), reverse",
259+
"id": "c791d17c54fbb061",
260+
"outputs": [],
261+
"execution_count": 17
262+
},
263+
{
264+
"metadata": {
265+
"ExecuteTime": {
266+
"end_time": "2025-02-01T12:19:50.274881Z",
267+
"start_time": "2025-02-01T12:19:50.258827Z"
268+
}
269+
},
270+
"cell_type": "code",
271+
"source": [
272+
"# rotate\n",
273+
"dq = deque('abcdefg')\n",
274+
"dq.rotate(1) # 向右旋转\n",
275+
"print(dq)\n",
276+
"dq = deque('abcdefg')\n",
277+
"dq.rotate(-1) # 向左旋转\n",
278+
"print(dq)"
279+
],
280+
"id": "c42d256bfff4c18c",
281+
"outputs": [
282+
{
283+
"name": "stdout",
284+
"output_type": "stream",
285+
"text": [
286+
"deque(['g', 'a', 'b', 'c', 'd', 'e', 'f'])\n",
287+
"deque(['b', 'c', 'd', 'e', 'f', 'g', 'a'])\n"
288+
]
289+
}
290+
],
291+
"execution_count": 21
292+
},
293+
{
294+
"metadata": {
295+
"ExecuteTime": {
296+
"end_time": "2025-02-01T12:20:48.499415Z",
297+
"start_time": "2025-02-01T12:20:48.488206Z"
298+
}
299+
},
300+
"cell_type": "code",
301+
"source": [
302+
"# maxlen\n",
303+
"d = deque(maxlen=3)\n",
304+
"for i in range(5):\n",
305+
" d.append(i)\n",
306+
"d"
307+
],
308+
"id": "b321ccdb15329e72",
309+
"outputs": [
310+
{
311+
"data": {
312+
"text/plain": [
313+
"deque([2, 3, 4], maxlen=3)"
314+
]
315+
},
316+
"execution_count": 22,
317+
"metadata": {},
318+
"output_type": "execute_result"
319+
}
320+
],
321+
"execution_count": 22
322+
},
323+
{
324+
"metadata": {},
325+
"cell_type": "code",
326+
"outputs": [],
327+
"execution_count": null,
328+
"source": "",
329+
"id": "e8fc087e5bfa2164"
330+
}
331+
],
332+
"metadata": {
333+
"kernelspec": {
334+
"display_name": "Python 3",
335+
"language": "python",
336+
"name": "python3"
337+
},
338+
"language_info": {
339+
"codemirror_mode": {
340+
"name": "ipython",
341+
"version": 2
342+
},
343+
"file_extension": ".py",
344+
"mimetype": "text/x-python",
345+
"name": "python",
346+
"nbconvert_exporter": "python",
347+
"pygments_lexer": "ipython2",
348+
"version": "2.7.6"
349+
}
350+
},
351+
"nbformat": 4,
352+
"nbformat_minor": 5
353+
}

AI Learn/Stage 2 Python Advanced/Chapter 1 Python Advanced Programing/哈希表.ipynb renamed to AI Learn/Stage 2 Python Advanced/Chapter 1 Python Advanced Programing/python_models_learn/hashlib.ipynb

File renamed without changes.

0 commit comments

Comments
 (0)