def combine_lists(list1, list2):
# Generate a new list containing the elements of list2
# Followed by the elements of list1 in reverse order
list3=list2.extend(list1.reverse())
return list3
Jamies_list = ["Alice", "Cindy", "Bobby", "Jan", "Peter"]
Drews_list = ["Mike", "Carol", "Greg", "Marcia"]
print(combine_lists(Jamies_list, Drews_list))
看看这是否是您正在寻找的:
list的
extend
方法修改当前列表,但不返回任何内容,因此您的表达式:list3=list2.extend(list1.reverse())
assign tolist3
valueNone
关于
reverse
也一样。它修改当前列表,但返回None
。您可以用reverse(list)
方法替换它.reverse
和.extend
都返回None
和palce中的突变列表试试这个
若要反转,请尝试这些
reversed(list2)
或[::-1]
中的任何一种方法。这些方法不会在适当的位置改变列表。注意:reversed(list2)
给出了一个迭代器相关问题 更多 >
编程相关推荐