-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0210-134-4.py
More file actions
37 lines (31 loc) · 1.38 KB
/
0210-134-4.py
File metadata and controls
37 lines (31 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding=utf-8
def search_keyword_index(s):
key_word = ['and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else',
'except', 'False', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'None',
'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'True', 'try', 'with', 'while', 'yield']
index_list = []
for word in key_word:
index_beg = 0
while word in s[index_beg:]:
word_begin_index = s.index(word, index_beg, len(s))
index_list += [i for i in range(word_begin_index, word_begin_index+len(word))]
index_beg = word_begin_index + len(word)
index_list.sort()
return index_list
file_read = open('pdf.py', 'r')
s_read = file_read.read()
file_read.close()
file_write = open('pdf_write.py', 'w')
s_write = ''
for index in range(len(s_read)): # 两种方法和下面的一样
if ('a' <= s_read[index] <= 'z') and (index not in search_keyword_index(s_read)):
s_write += s_read[index].upper()
else:
s_write += s_read[index]
# 两种方法和上面的一样
# for index in range(len(s_read)):
# if ('a' <= s_read[index] <= 'z') and (index not in search_keyword_index(s_read)):
# s_read = s_read[:index] + s_read[index].upper() + s_read[(index + 1):]
print(s_write)
file_write.write(s_write)
file_write.close()