Skip to content

Latest commit

History

History
21 lines (16 loc) · 468 Bytes

File metadata and controls

21 lines (16 loc) · 468 Bytes

翻转列表内的元素

用到listpopappend方法。

# -*- coding: utf -8 -*-fromrandomimportrandrange# 随机生成指定范围内的数字defrevers(seq, L=None):
whileseq:
ifLisNone:
L= []
L.append(seq.pop())
returnLif__name__=="__main__":
lst= [randrange(100) for_inrange(10)]
print('This is original list\n', lst)
print('This is reversed list\n', revers(lst))