题目:
翻转list,要求不使用新的list,只能在原list上完成
例子:
None -> None
[] -> []
[1,2,3,4] -> [4,3,21]
['a', 'b', 'c'] -> ['c', 'b', 'a']
def reverseList(chars):
if chars is None:
return None
if len(chars) <= 1:
return chars
index = len(chars)//2
for i in range(index):
chars[i], chars[-i-1] = chars[-i-1], chars[i]
return chars
alist = [1,2,3,4,5]
blist = [4]
clist = None
print(reverseList(alist))