Pesky reverse()

engsolnom at ipns.com engsolnom at ipns.com
Thu Jan 8 21:28:34 EST 2004


I need to use the built-in method 'reverse', but notice strange behavior.
Foe example:

print my_list.reverse()  doesn't work.

new_list = my_list.reverse() doesn't work.

my_list.reverse()
print my_list does work. (displays reversed list)

But  I want both a 'forward' and 'reverse' list:

new_list = my+list  # should save a 'forward' copy, right? Nope
my_list.reverse() actually reverses both copies, since Python is a bit too
helpful sometimes, and I understand why.

So the question is, how do I get a forward and reverse list?

Thanks......Norm. 





More information about the Python-list mailing list