Pesky reverse()

Elaine Jackson elainejackson7355 at home.com
Fri Jan 9 13:43:28 EST 2004


>>> list1=[1,2,3]
>>> list2=list1[:]   ##  "cloning"
>>> list1.reverse()==None
1
>>> list1
[3, 2, 1]
>>> list2
[1, 2, 3]


<engsolnom at ipns.com> wrote in message
news:3t3svvs7ni8l8jnn1l1v60oogirqoaa85f at 4ax.com...
|
| 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