File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ `` `
Original file line number Diff line number Diff line change 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))
You can’t perform that action at this time.
0 commit comments