Skip to content

Commit 77cd96e

Browse files
guozhen3guozhen3
guozhen3
authored and
guozhen3
committed
发起第一个Python小项目
1 parent 0423c87 commit 77cd96e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,45 @@
3131

3232
允许按照要求转载,但禁止用于任何商用目的。
3333

34+
## 进行中Python小项目
35+
36+
上下文关键字(KWIC, Key Word In Context)是最常见的多行协调显示格式。
37+
38+
此小项目描述:输入一系列句子,给定一个给定单词,每个句子中至少会出现一次给定单词。目标输出,给定单词按照KWIC显示,KWIC显示的基本要求:待查询单词居中,前面`pre`序列右对齐,后面`post`序列左对齐,待查询单词前和后长度相等,若输入句子无法满足要求,用空格填充。
39+
40+
输入参数:输入句子sentences, 待查询单词selword, 滑动窗口长度`window_len`
41+
42+
举例,输入如下六个句子,给定单词`secure`,输出如下字符串:
43+
44+
```python
45+
pre keyword post
46+
47+
welfare , and secure the blessings of
48+
nations , and secured immortal glory with
49+
, and shall secure to you the
50+
cherished . To secure us against these
51+
defense as to secure our cities and
52+
I can to secure economy and fidelity
53+
```
54+
55+
请补充实现下面函数:
56+
57+
```python
58+
def kwic(sentences: List[str], selword: str, window_len: int) -> str:
59+
"""
60+
:type: sentences: input sentences
61+
:type: selword: selected word
62+
:type: window_len: window length
63+
"""
64+
```
65+
66+
更多KWIC显示参考如下:
67+
68+
http://dep.chs.nihon-u.ac.jp/english_lang/tukamoto/kwic_e.html
69+
70+
71+
72+
3473
## Python 原创教程
3574
这是经过很久打磨的一个Python教程,全部是个人原创,已首发在公众号,并且托管在我的[个人网站](http://www.zglg.work/python-level/)。想系统入门Python的欢迎学习:
3675

0 commit comments

Comments
 (0)