Skip to content

Commit 1b9a638

Browse files
committed
add revers
1 parent 8af0441 commit 1b9a638

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

resvers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## 翻转列表内的元素
2+
3+
用到`list``[pop](https://docs.python.org/3.5/tutorial/datastructures.html)``append`方法
4+
5+
```python
6+
# -*- coding: utf -8 -*-
7+
8+
from random import randrange
9+
10+
def revers(seq, L=None):
11+
while seq:
12+
if L is None:
13+
L = []
14+
L.append(seq.pop())
15+
return L
16+
17+
if __name__ == "__main__":
18+
lst = [randrange(100) for _ in range(10)]
19+
print('This is original list\n', lst)
20+
print('This is reversed list\n', revers(lst))
21+
```

revers.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## 翻转列表内的元素
2+
用到list的pop和append方法。
3+
4+
# -*- coding: utf -8 -*-
5+
6+
from random import randrange
7+
8+
def revers(seq, L=None):
9+
while seq:
10+
if L is None:
11+
L = []
12+
L.append(seq.pop())
13+
return L
14+
15+
if __name__ == "__main__":
16+
lst = [randrange(100) for _ in range(10)]
17+
print('This is original list\n', lst)
18+
print('This is reversed list\n', revers(lst))

0 commit comments

Comments
 (0)