str = "this is a good day"
list = str.split()
print(list)
temp = []
flag = 0
while len(list)>0:
temp.append(list.pop())
print(temp)
str = 'this is a good day'
list = str.split()
lo = 0
hi = len(list)-1
while lo<hi:
temp = list[lo]
list[lo] = list[hi]
list[hi] = temp
lo+=1
hi-=1
print(list)
str = 'this is a good day'
list = str.split()
def reserve(list, lo, hi):
if lo<hi:
temp = list[lo]
list[lo] = list[hi]
list[hi] = temp
reserve(list, lo+1, hi-1)
reserve(list, 0, len(list)-1)
print(list)
网友评论