Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 468 Bytes

resver.md

File metadata and controls

21 lines (16 loc) · 468 Bytes

翻转列表内的元素

用到listpopappend方法。

# -*- coding: utf -8 -*-

from random import randrange # 随机生成指定范围内的数字

def revers(seq, L=None):
    while seq:
        if L is None:
            L = []
        L.append(seq.pop())
    return L

if __name__ == "__main__":
    lst = [randrange(100) for _ in range(10)]
    print('This is original list\n', lst)
    print('This is reversed list\n', revers(lst))