Skip to content

Commit 62ba694

Browse files
committed
complete 0003
1 parent 7930980 commit 62ba694

1 file changed

Lines changed: 314 additions & 8 deletions

File tree

‎jiangqideng/000.ipynb‎

Lines changed: 314 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"### 第0000题"
7+
"### 第0000题\n",
8+
"将你的 QQ 头像(或者微博头像)右上角加上红色的数字,类似于微信未读信息数量那种提示效果。 类似于图中效果"
89
]
910
},
1011
{
@@ -45,7 +46,8 @@
4546
"collapsed": true
4647
},
4748
"source": [
48-
"### 第0001题"
49+
"### 第0001题\n",
50+
"做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激活码(或者优惠券),使用 Python 如何生成 200 个激活码(或者优惠券)?"
4951
]
5052
},
5153
{
@@ -79,12 +81,13 @@
7981
"cell_type": "markdown",
8082
"metadata": {},
8183
"source": [
82-
"### 第0002题"
84+
"### 第0002题\n",
85+
"将 0001 题生成的 200 个激活码(或者优惠券)保存到 MySQL 关系型数据库中。"
8386
]
8487
},
8588
{
8689
"cell_type": "code",
87-
"execution_count": 7,
90+
"execution_count": 5,
8891
"metadata": {
8992
"collapsed": false
9093
},
@@ -106,22 +109,325 @@
106109
" ticket_code CHAR(100))\"\"\"\n",
107110
"cursor.execute(sql)\n",
108111
"\n",
109-
"for i in range(1, 101):\n",
112+
"for i in range(1, 201):\n",
110113
" ticket = gen_a_ticket(100).next()\n",
111114
" sql = \"INSERT INTO python_tickets VALUES ('%d', '%s')\" % (i, ticket)\n",
112115
" cursor.execute(sql)\n",
113116
" db.commit()\n",
114117
"db.close()"
115118
]
116119
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {},
123+
"source": [
124+
"### 第0003题\n",
125+
"将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。"
126+
]
127+
},
117128
{
118129
"cell_type": "code",
119-
"execution_count": null,
130+
"execution_count": 17,
131+
"metadata": {
132+
"collapsed": false
133+
},
134+
"outputs": [
135+
{
136+
"name": "stdout",
137+
"output_type": "stream",
138+
"text": [
139+
"BXDOGQPIPQPMEDPLOJRAOAFUOFJPMBMWANNVFDYMFGXFKRQKWBYQOOJRQGTIJYEQKOKBYTSXILDFULVNHYAKQYRKMILWMCPNXAKQ\n"
140+
]
141+
}
142+
],
143+
"source": [
144+
"import numpy as np, string\n",
145+
"def gen_a_ticket(tickets_len):\n",
146+
" idx = np.random.randint(0, 25, tickets_len)\n",
147+
" letters = np.array(list(string.ascii_uppercase))\n",
148+
" s = letters[idx].tostring()\n",
149+
" yield s\n",
150+
"\n",
151+
"import redis\n",
152+
"rd = redis.Redis(host='localhost', port=6379, db=0)\n",
153+
"for i in range(1, 201):\n",
154+
" ticket = gen_a_ticket(100).next()\n",
155+
" rd.set(i, ticket)\n",
156+
"rd.save()\n",
157+
"\n",
158+
"# test\n",
159+
"print rd.get(55)"
160+
]
161+
},
162+
{
163+
"cell_type": "markdown",
120164
"metadata": {
121165
"collapsed": true
122166
},
123-
"outputs": [],
124-
"source": []
167+
"source": [
168+
"### 第0004题\n",
169+
"任一个英文的纯文本文件,统计其中的单词出现的个数。"
170+
]
171+
},
172+
{
173+
"cell_type": "code",
174+
"execution_count": 41,
175+
"metadata": {
176+
"collapsed": false
177+
},
178+
"outputs": [
179+
{
180+
"name": "stdout",
181+
"output_type": "stream",
182+
"text": [
183+
"you 20\n",
184+
"the 18\n",
185+
"to 17\n",
186+
"if 11\n",
187+
"your 11\n",
188+
"and 10\n",
189+
"file 10\n",
190+
"or 10\n",
191+
"pages 9\n",
192+
"as 8\n",
193+
"github 8\n",
194+
"with 8\n",
195+
"in 7\n",
196+
"that 7\n",
197+
"have 6\n",
198+
"jekyll 6\n",
199+
"layout 6\n",
200+
"page 6\n",
201+
"these 6\n",
202+
"by 5\n",
203+
"can 5\n",
204+
"don 5\n",
205+
"ll 5\n",
206+
"markdown 5\n",
207+
"now 5\n",
208+
"repository 5\n",
209+
"site 5\n",
210+
"we 5\n",
211+
"all 4\n",
212+
"an 4\n",
213+
"are 4\n",
214+
"be 4\n",
215+
"default 4\n",
216+
"for 4\n",
217+
"from 4\n",
218+
"index 4\n",
219+
"of 4\n",
220+
"on 4\n",
221+
"any 3\n",
222+
"build 3\n",
223+
"config 3\n",
224+
"doesn 3\n",
225+
"existing 3\n",
226+
"features 3\n",
227+
"files 3\n",
228+
"may 3\n",
229+
"publishing 3\n",
230+
"readme 3\n",
231+
"theme 3\n",
232+
"title 3\n",
233+
"use 3\n",
234+
"website 3\n",
235+
"adding 2\n",
236+
"additional 2\n",
237+
"affect 2\n",
238+
"at 2\n",
239+
"changes 2\n",
240+
"content 2\n",
241+
"elsewhere 2\n",
242+
"exclude 2\n",
243+
"expect 2\n",
244+
"explicitly 2\n",
245+
"feel 2\n",
246+
"few 2\n",
247+
"front 2\n",
248+
"get 2\n",
249+
"how 2\n",
250+
"it 2\n",
251+
"just 2\n",
252+
"like 2\n",
253+
"look 2\n",
254+
"matter 2\n",
255+
"more 2\n",
256+
"most 2\n",
257+
"need 2\n",
258+
"re 2\n",
259+
"set 2\n",
260+
"shouldn 2\n",
261+
"sites 2\n",
262+
"software 2\n",
263+
"specify 2\n",
264+
"such 2\n",
265+
"there 2\n",
266+
"three 2\n",
267+
"via 2\n",
268+
"100th 1\n",
269+
"above 1\n",
270+
"activate 1\n",
271+
"add 1\n",
272+
"advanced 1\n",
273+
"again 1\n",
274+
"allow 1\n",
275+
"already 1\n",
276+
"although 1\n",
277+
"appears 1\n",
278+
"assign 1\n",
279+
"authoring 1\n",
280+
"automatically 1\n",
281+
"based 1\n",
282+
"begin 1\n",
283+
"begins 1\n",
284+
"behind 1\n",
285+
"bring 1\n",
286+
"browse 1\n",
287+
"browser 1\n",
288+
"but 1\n",
289+
"clicks 1\n",
290+
"commit 1\n",
291+
"context 1\n",
292+
"continue 1\n",
293+
"control 1\n",
294+
"course 1\n",
295+
"create 1\n",
296+
"customizable 1\n",
297+
"customizations 1\n",
298+
"dependency 1\n",
299+
"directive 1\n",
300+
"directory 1\n",
301+
"disable 1\n",
302+
"dissimilar 1\n",
303+
"docs 1\n",
304+
"document 1\n",
305+
"documentation 1\n",
306+
"doing 1\n",
307+
"each 1\n",
308+
"easily 1\n",
309+
"either 1\n",
310+
"exact 1\n",
311+
"example 1\n",
312+
"exist 1\n",
313+
"experience 1\n",
314+
"explicit 1\n",
315+
"familiar 1\n",
316+
"far 1\n",
317+
"fewer 1\n",
318+
"find 1\n",
319+
"first 1\n",
320+
"folder 1\n",
321+
"given 1\n",
322+
"gotchas 1\n",
323+
"h1 1\n",
324+
"h2 1\n",
325+
"h3 1\n",
326+
"happy 1\n",
327+
"heading 1\n",
328+
"headings 1\n",
329+
"html 1\n",
330+
"implemented 1\n",
331+
"improvements 1\n",
332+
"interested 1\n",
333+
"interface 1\n",
334+
"iterates 1\n",
335+
"its 1\n",
336+
"know 1\n",
337+
"layouts 1\n",
338+
"line 1\n",
339+
"list 1\n",
340+
"matches 1\n",
341+
"md 1\n",
342+
"metadata 1\n",
343+
"minimal 1\n",
344+
"namely 1\n",
345+
"navigate 1\n",
346+
"needing 1\n",
347+
"nojekyll 1\n",
348+
"not 1\n",
349+
"null 1\n",
350+
"one 1\n",
351+
"open 1\n",
352+
"opting 1\n",
353+
"optional 1\n",
354+
"other 1\n",
355+
"overriding 1\n",
356+
"own 1\n",
357+
"places 1\n",
358+
"please 1\n",
359+
"plugins 1\n",
360+
"possible 1\n",
361+
"potential 1\n",
362+
"process 1\n",
363+
"project 1\n",
364+
"publish 1\n",
365+
"questions 1\n",
366+
"quickly 1\n",
367+
"reason 1\n",
368+
"rendered 1\n",
369+
"requires 1\n",
370+
"root 1\n",
371+
"safely 1\n",
372+
"saving 1\n",
373+
"scenes 1\n",
374+
"separated 1\n",
375+
"serve 1\n",
376+
"settings 1\n",
377+
"should 1\n",
378+
"simplify 1\n",
379+
"simply 1\n",
380+
"so 1\n",
381+
"some 1\n",
382+
"source 1\n",
383+
"specified 1\n",
384+
"step 1\n",
385+
"steps 1\n",
386+
"styles 1\n",
387+
"tabs 1\n",
388+
"them 1\n",
389+
"things 1\n",
390+
"those 1\n",
391+
"through 1\n",
392+
"titles 1\n",
393+
"top 1\n",
394+
"touch 1\n",
395+
"transparent 1\n",
396+
"two 1\n",
397+
"unset 1\n",
398+
"unstyled 1\n",
399+
"us 1\n",
400+
"users 1\n",
401+
"values 1\n",
402+
"vendored 1\n",
403+
"want 1\n",
404+
"web 1\n",
405+
"what 1\n",
406+
"when 1\n",
407+
"which 1\n",
408+
"while 1\n",
409+
"will 1\n",
410+
"within 1\n",
411+
"would 1\n",
412+
"yaml 1\n"
413+
]
414+
}
415+
],
416+
"source": [
417+
"#coding=utf-8\n",
418+
"from sklearn.feature_extraction.text import CountVectorizer\n",
419+
"import numpy as np\n",
420+
"vectorizer = CountVectorizer()\n",
421+
"text_path = r\"C:\\Users\\jiang\\Desktop\\Github_Pages.txt\" #utf-8 without BOM\n",
422+
"with open(text_path, 'r') as f:\n",
423+
" s = f.readlines()\n",
424+
" X = vectorizer.fit_transform(s)\n",
425+
"words = vectorizer.get_feature_names()\n",
426+
"counts = np.sum(X.toarray(), 0).tolist()\n",
427+
"results = sorted(zip(words, counts), key=lambda x:x[1], reverse=True)\n",
428+
"for word, count in results: # print results\n",
429+
" print word, count"
430+
]
125431
}
126432
],
127433
"metadata": {

0 commit comments

Comments
 (0)