Skip to content

Commit f439892

Browse files
author
Jiang
committed
移除了一个未使用的函数;改写 invert 函数,让它更 pythonic
1 parent 91be914 commit f439892

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

ebook/code/python/1.1:左旋转字符串.py ebook/code/python/1.1:字符的移动.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@
1717
# Tools
1818

1919

20-
def swap(s, i, j):
21-
'''交换s中i和i位置的元素
22-
Author: Jasonwbw([email protected])
23-
Editor:
24-
25-
Args:
26-
s : 要交换的列表
27-
i : 索引位置i
28-
j : 索引位置j
29-
'''
30-
s[i], s[j] = s[j], s[i]
31-
32-
3320
def left_shift_one(s, i, j):
3421
'''s从i(包含)到j(不包含),左移一位
3522
Author: Jasonwbw([email protected])
@@ -97,9 +84,7 @@ def invert(s, start, end):
9784
'''
9885
n = end - start + 1
9986
for i in xrange(n / 2):
100-
t = s[start + i]
101-
s[start + i] = s[end - i]
102-
s[end - i] = t
87+
s[start + i], s[end - i] = s[end - i], s[start +i]
10388

10489

10590
def invert_solution(s, m):

0 commit comments

Comments
 (0)