所以我正在尝试获取 2 个数字列表;切片第一个列表,反转切片列表的顺序,然后将其添加到第二个列表并打印新列表。当我运行并将所有输入放入时,我只会得到一个空列表。你们能帮我找出我哪里出错了吗?
def transform(list1,list2,r1,r2):
rev_list=[]
list1=''
list2=''
l1=list1.split(',')
l2=list2.split(',')
slice_l1=l1[r1:r2]
for i in reversed(slice_l1):
rev_list.extend(i)
new_list=l2+rev_list
return new_list
def main():
user_input_l1=input("Please enter a list of numbers separated by a comma (,): ")
user_input_l2=input("Please enter a second list of numbers separated by a comma (,): ")
user_input_r1=int(input("Please enter the beginning index for slice: "))
user_input_r2=int(input("Please enter the ending index for slice: "))
new_list=transform(user_input_l1,user_input_l2,user_input_r1,user_input_r2)
print("Your new list is",new_list)
print(type(new_list))
if __name__=="__main__":
main()
谢谢大家。