In Python, what is the best way to create a new list whose items are the same as those of some other list, but in reverse order? (I don't want to modify the existing list in place.)
Here is one solution that has occurred to me:
new_list = list(reversed(old_list))
It's also possible to duplicate old_list
then reverse the duplicate in place:
new_list = list(old_list) # or `new_list = old_list[:]`
new_list.reverse()
Is there a better option that I've overlooked? If not, is there a compelling reason (such as efficiency) to use one of the above approaches over the other?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…