Skip to content

Commit fb38343

Browse files
authored
Merge pull request #2412 from xinwu2064/master
自学训练营学习1群 1901010060 day5homework
2 parents 7ac46c6 + b99c295 commit fb38343

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
list_1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
2+
list_1.reverse() #反转元素的位置
3+
print(list_1)
4+
5+
#数组拼接为字符串
6+
list_1=''.join(str(i) for i in list_1) #list1=“”是不带空格的
7+
print(list_1)
8+
9+
#切片的方式取出第三到第八个字符
10+
list_2=list_1[2:8] #空格也算字符
11+
print(list_2)
12+
13+
#将获得字符串进行翻转
14+
list_3=list_2[::-1]
15+
print(list_3)
16+
17+
#将结果转换为INT类型
18+
int_1=int(list_3)
19+
print(int_1)
20+
21+
#分别转换为二进制,八进制,十六进制
22+
print('转换成二进制为:',bin(int_1))
23+
print('转换成八进制为:',oct(int_1))
24+
print('转换成十六进制为:',hex(int_1))
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
text = '''
2+
The Zen of Python, by Tim Peters
3+
Beautiful is better than ugly.
4+
Explicit is better than implicit.
5+
Simple is better than complex.
6+
Complex is better than complicated.
7+
Flat is better than nested.
8+
Sparse is better than dense.
9+
Readability counts.
10+
Special cases aren't special enough to break the rules.
11+
Although practicality beats purity.
12+
Errors should never pass silently.
13+
Unless explicitly silenced.
14+
In the face of ambxiguity, refuse the temptation to guess.
15+
There should be one-- and preferably only one --obvious way to do it.
16+
Although that way may not be obvious at first unless you're Dutch.
17+
Now is better than never.
18+
Although never is often better than *right* now.
19+
If the implementation is hard to explain, it's a bad idea.
20+
If the implementation is easy to explain, it may be a good idea.
21+
Namespaces are one honking great idea -- let's do more of those!
22+
'''
23+
24+
text=text.replace(',','').replace('.','').replace('--','').replace('!','').replace('*','') #去除标点符号(没有找到更好的办法,如果文本格式很多怎么办?)
25+
text=text.lower() #把单词全部变为小写
26+
text=text.split() #把字符串分割成单个单词列表
27+
28+
dict={}
29+
for x in text:
30+
if x in dict:
31+
dict[x]=dict[x]+1
32+
else:
33+
dict[x]=1
34+
text_1 = sorted(dict.items(), key=lambda y: y[1], reverse=True) #key为排序依据,y【0】为key,1为y,这里不太懂,reverse为true时降序。
35+
36+
print(text_1)
37+
38+
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
text = '''
2+
The Zen of Python, by Tim Peters
3+
Beautiful is better than ugly.
4+
Explicit is better than implicit.
5+
Simple is better than complex.
6+
Complex is better than complicated.
7+
Flat is better than nested.
8+
Sparse is better than dense.
9+
Readability counts.
10+
Special cases aren't special enough to break the rules.
11+
Although practicality beats purity.
12+
Errors should never pass silently.
13+
Unless explicitly silenced.
14+
In the face of ambxiguity, refuse the temptation to guess.
15+
There should be one-- and preferably only one --obvious way to do it.
16+
Although that way may not be obvious at first unless you're Dutch.
17+
Now is better than never.
18+
Although never is often better than *right* now.
19+
If the implementation is hard to explain, it's a bad idea.
20+
If the implementation is easy to explain, it may be a good idea.
21+
Namespaces are one honking great idea -- let's do more of those!
22+
'''
23+
24+
25+
text1 = text.replace("better","worse")
26+
text2 =text1.split(" ")
27+
d=[]
28+
for i in text2:
29+
if 'ea' not in i:
30+
d.append(i)
31+
else:
32+
continue
33+
e=' '
34+
f=e.join(d)
35+
g = f.swapcase()
36+
h = g.split()
37+
j = sorted(h)
38+
k = ' '
39+
l = k.join(j)
40+
print(l)
41+

0 commit comments

Comments
 (0)