Skip to content

Commit 38ae3cb

Browse files
committed
d5
1 parent bd7b8dc commit 38ae3cb

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
array=[0,1,2,3,4,5,6,7,8,9]
2+
3+
# 翻转
4+
array.reverse()
5+
print(array)
6+
7+
# 拼接成字符串
8+
c = [9,8,7,6,5,4,3,2,1,0]
9+
array = [str(i) for i in array]
10+
array = ''.join(array)
11+
print(array)
12+
13+
# 取出第三到第八个字符(包含第三到第八个字符)")
14+
array = array[2:8]
15+
print(array)
16+
17+
# 翻转
18+
array = array[::-1]
19+
print(array)
20+
21+
# 转换为int类型
22+
array = int(array)
23+
print(array)
24+
25+
# 分别转换为二、八、十六进制
26+
two = bin(array)
27+
eight = oct(array)
28+
sixteen = hex(array)
29+
30+
# 分别输出三种结果
31+
print(two)
32+
print(eight)
33+
print(sixteen)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 字符串样本text
2+
text = '''
3+
The Zen of Python, by Tim Peters
4+
Beautiful is better than ugly.
5+
Explicit is better than implicit.
6+
Simple is better than complex.
7+
Complex is better than complicated.
8+
Flat is better than nested.
9+
Sparse is better than dense.
10+
Readability counts.
11+
Special cases aren't special enough to break the rules.
12+
Although practicality beats purity.
13+
Errors should never pass silently.
14+
Unless explicitly silenced.
15+
In the face of ambxiguity, refuse the temptation to guess.
16+
There should be one-- and preferably only one --obvious way to do it.
17+
Although that way may not be obvious at first unless you're Dutch.
18+
Now is better than never.
19+
Although never is often better than *right* now.
20+
If the implementation is hard to explain, it's a bad idea.
21+
If the implementation is easy to explain, it may be a good idea.
22+
Namespaces are one honking great idea -- let's do more of those!
23+
'''
24+
25+
text = text.replace(',',' ').replace('.',' ').replace('--',' ').replace('!',' ').replace('*',' ')
26+
text = text.lower()
27+
text = text.split()
28+
29+
dict = {}
30+
for i in text:
31+
count = text.count(i)
32+
r1 = {i:count}
33+
dict.update(r1)
34+
35+
dict = sorted(dict.items(),key = lambda x:x[1],reverse = True)
36+
print(dict)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# 字符串样本text
2+
text = '''
3+
The Zen of Python, by Tim Peters
4+
Beautiful is better than ugly.
5+
Explicit is better than implicit.
6+
Simple is better than complex.
7+
Complex is better than complicated.
8+
Flat is better than nested.
9+
Sparse is better than dense.
10+
Readability counts.
11+
Special cases aren't special enough to break the rules.
12+
Although practicality beats purity.
13+
Errors should never pass silently.
14+
Unless explicitly silenced.
15+
In the face of ambxiguity, refuse the temptation to guess.
16+
There should be one-- and preferably only one --obvious way to do it.
17+
Although that way may not be obvious at first unless you're Dutch.
18+
Now is better than never.
19+
Although never is often better than *right* now.
20+
If the implementation is hard to explain, it's a bad idea.
21+
If the implementation is easy to explain, it may be a good idea.
22+
Namespaces are one honking great idea -- let's do more of those!
23+
'''
24+
25+
# 将text里的better全部替换成worse
26+
text = text.replace('better','worse')
27+
28+
# 将单词中包含ea的单词剔除
29+
text1 = text.split()
30+
character = 'ea'
31+
text2 = []
32+
for i in text1:
33+
if i.find(character) == -1:
34+
text2.append(i)
35+
36+
# 将字母进行大小写翻转
37+
text3 = ' '.join(text2)
38+
text3 = text3.swapcase()
39+
print(text3)
40+
41+
#将所有单词按a...z升序排序,并输出结果
42+
text3 = text3.lower()
43+
text4 = text3.split()
44+
print(sorted(text4))
45+
46+

0 commit comments

Comments
 (0)