Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions exercises/1901100209/1001S02E05/1001S02E05_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
text=[0,1,3,4,5,6,7,8,9]
text.reverse()
print("数字反转",text)

joined_str="".join([str(i) for i in text])
print("拼接成字符串",joined_str)

slice_ed=joined_str[2:8]
print("切片",slice_ed)

reverse_str=slice_ed[::-1]
print("反转",reverse_str)
slice_int=int(reverse_str)
print("转换为int类型",slice_int)
print("转换为二进制",bin(slice_int))
print("转换为八进制",oct(slice_int))
print("转换为十六进制",hex(slice_int))
39 changes: 39 additions & 0 deletions exercises/1901100209/1001S02E05/1001S02E05_stats_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
text = '''
The Zen of Python, by Tim Peters


Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambxiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
elements=text.split()
words=[]
symbols=",.*-!"
for element in elements:
for symbol in symbols:
element=element.replace(symbol,"")
if len(element):
words.append(element)
print("正常英文单词",words)
counter={}
word_set=set(words)
for word in word_set:
counter[word]=words.count(word)
print("英文单词出现的次数",counter)
print("从大到小输出单词及其次数",sorted(counter.items(),key=lambda x: x[1],reverse=True))
38 changes: 38 additions & 0 deletions exercises/1901100209/1001S02E05/1001S02E05_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
text = '''
The Zen of Python, by Tim Peters


Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambxiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
text=text.replace('better','worse')
print(text)
text1=text.split()
word="ea"
worde=[]
for i in text1:
if i.find(word)>-1:
del i
else:
worde.append(i)
print("将ea删除",worde)
turned=[i.swapcase() for i in worde]
print("大小写翻转",turned)
print("升序排序",sorted(turned))
64 changes: 64 additions & 0 deletions exercises/1901100209/1001S02E06/1001S02E06_stats_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
def stats_text_en(text):
"""统计参数中英文单词出现的次数,并按降序排列数组"""
elements=text.split()
words=[]
symbols=",.*-!"
for element in elements:
for symbol in symbols:
element=element.replace(symbol,"")
if len(element):
words.append(element)
print("正常英文单词",words)
counter={}
word_set=set(words)
for word in word_set:
counter[word]=words.count(word)
return sorted(counter.items(),key=lambda x: x[1],reverse=True)

def stats_text_cn(text):
"""统计汉字出现的次数,并按降序排列数组"""
cn_courter=[]
for courter in text:
if '\u4e00'<= courter <='\u9fff':
cn_courter.append(courter)
counter_text={}
for i in set(cn_courter):
counter_text[i]=cn_courter.count(i)
return sorted(counter_text.items(),key=lambda x: x[1],reverse=True)

en_text = '''
The Zen of Python, by Tim Peters


Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambxiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
cn_text="""
python学习
好好学习
天天向上
"""
first=stats_text_en(en_text)
print(first)
second=stats_text_cn(cn_text)
print(second)



12 changes: 12 additions & 0 deletions exercises/1901100209/d07/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from mymodule import stats_word
smaple_text="""
好好学习,天天向上,努力工作
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense."""

result=stats_word.stats_text(smaple_text)
print(result)
68 changes: 68 additions & 0 deletions exercises/1901100209/d07/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
def stats_text_en(text):
"""统计参数中英文单词出现的次数,并按降序排列数组"""
elements=text.split()
words=[]
symbols=",.*-!"
for element in elements:
for symbol in symbols:
element=element.replace(symbol,"")
if len(element):
words.append(element)
print("正常英文单词",words)
counter={}
word_set=set(words)
for word in word_set:
counter[word]=words.count(word)
return sorted(counter.items(),key=lambda x: x[1],reverse=True)

def stats_text_cn(text):
"""统计汉字出现的次数,并按降序排列数组"""
cn_courter=[]
for courter in text:
if '\u4e00'<= courter <='\u9fff':
cn_courter.append(courter)
counter_text={}
for i in set(cn_courter):
counter_text[i]=cn_courter.count(i)
return sorted(counter_text.items(),key=lambda x: x[1],reverse=True)

def stats_text(text):
"""输出合并词频统计结果"""
return stats_text_en(text) + stats_text_cn(text)



en_text = '''
The Zen of Python, by Tim Peters


Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambxiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
cn_text="""
python学习
好好学习
天天向上
"""
if __name__ == "__main__":
first=stats_text_en(en_text)
print("统计英文单词出现次数: ",first)
second=stats_text_cn(cn_text)
print("统计汉字出现次数: ",second)
15 changes: 15 additions & 0 deletions exercises/1901100209/d08/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from mymodule import stats_word
import traceback

def test_traceback():
try:
stats_word.stats_text(1)
except Exception as e:
print('texs_traceback =>',e)
print(traceback.format_exc())




if __name__ == '__main__':
test_traceback()
74 changes: 74 additions & 0 deletions exercises/1901100209/d08/mymodule/stats_word.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
def stats_text_en(text):
"""统计参数中英文单词出现的次数,并按降序排列数组"""
if not isinstance(text,str):
raise ValueError("参数必须是字符串类型,输入类型 %s" % type(text))
elements=text.split()
words=[]
symbols=",.*-!"
for element in elements:
for symbol in symbols:
element=element.replace(symbol,"")
if len(element) and element.isascii():
words.append(element)
print("正常英文单词",words)
counter={}
word_set=set(words)
for word in word_set:
counter[word]=words.count(word)
return sorted(counter.items(),key=lambda x: x[1],reverse=True)

def stats_text_cn(text):
"""统计汉字出现的次数,并按降序排列数组"""
if not isinstance(text,str):
raise ValueError("参数必须是字符串类型,输入类型 %s" % type(text))
cn_courter=[]
for courter in text:
if '\u4e00'<= courter <='\u9fff':
cn_courter.append(courter)
counter_text={}
for i in set(cn_courter):
counter_text[i]=cn_courter.count(i)
return sorted(counter_text.items(),key=lambda x: x[1],reverse=True)

def stats_text(text):
"""输出合并词频统计结果"""
if not isinstance(text,str):
raise ValueError("参数必须是字符串类型,输入类型 %s" % type(text))
return stats_text_en(text) + stats_text_cn(text)



en_text = '''
The Zen of Python, by Tim Peters


Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambxiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
'''
cn_text="""
python学习
好好学习
天天向上
"""
if __name__ == "__main__":
first=stats_text_en(en_text)
print("统计英文单词出现次数: ",first)
second=stats_text_cn(cn_text)
print("统计汉字出现次数: ",second)