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
2 changes: 2 additions & 0 deletions exercises/1901100362/1001S02E02_hello_python.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@


print('hello world!')
23 changes: 23 additions & 0 deletions exercises/1901100362/1001S02E05_array.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
arr = [0,1,2,3,4,5,6,7,8,9]
#翻转arr数组
arr.reverse()

#将数组元素拼接成字符串
l1 = [str(a) for a in arr]
s1 = ''.join(l1)
print(s1)

#对字符串切片,取出第三到第八个字符
s2 = s1[2:9]
print(s2)
#对字符串进行翻转
s3 = s2[::-1]
print(s3)
#转换成十进制
in1 = int(s3)
#转换成8禁制
oct1 = oct(in1)
#转换成16进制
hex1 = hex(in1)
print(f'{oct1} \n{hex1}')

63 changes: 63 additions & 0 deletions exercises/1901100362/1001S02E05_stats_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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. 9 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('-','').replace('.','').replace('*','').replace('!','').replace(',','')

word = text.split()
wordDic = {}


for key in word:
if key in wordDic:
wordDic[key] +=1
else:
wordDic[key] = 1

#print(wordDic)
print('----------------------------------------------')

#返回元素魏元组的列表
wordSort = sorted(wordDic.items(),key = lambda x:x[1],reverse=True)
#print(wordSort)
print(dict(wordSort))





















68 changes: 68 additions & 0 deletions exercises/1901100362/1001S02E05_string.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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. 9 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!'''

#把better替换成worse
t1 = text.replace('better','worse')
print(t1)
print("-------------------------------------------------------------------------------")

#删除字符串中的带ea的单词
l1 = text.strip().split()
l2 = []
for i in range(len(l1)):
if l1[i].find('ea') == -1:
l2.append(l1[i])

s1 = ' '.join(l2)

#大小写转换
s2 = s1.swapcase()
print(s2)
print('---------------------------------------------------------------------------------')

#按单词排序
s3 = s2.replace('*','').replace('.','').replace('-','').replace('!','').replace(',','')
l3 = s3.split()
l4 = sorted(l3)
print(sorted(l3))

print('----------------------------------')
s4 = ' '.join(l4)
print(s4)

#print(s3)
#l3 = []
#for a in s2.split(','):
# for b in a.split():

# l3.append(b.strip('*').strip('.').strip('-').strip('9').strip('!'))

#去掉列表中的空字符元素
#l4 = list(filter(None,l3))

#可以用 sort和sorted两种方法对列表元素排序
#方法1:sort函数
#l4.sort()
#s3 = ','.join(l4)
#print(s3)
#方法二:sorted函数
#print(sorted(l4))