Immutable list reverse function
Martin Sjögren
martin at strakt.com
Thu Jul 19 07:45:35 EDT 2001
Is there a "good" way to write a fast reverse function for immutable
lists?
I tried this:
def reverse(list):
l = len(list)
return [ list[l-i-1] for i in range(l) ]
It works, but it's obviously not backwards compatible.
Any suggestions?
What I want to do is basically this:
>>> foo(reverse(create_a_list()))
Instead of having to:
>>> list = create_a_list()
>>> list.reverse()
>>> foo(list)
Hints appreciated
Martin
--
Martin Sjögren
martin at strakt.com ICQ : 41245059
Phone: +46 (0)31 405242 Cell: +46 (0)739 169191
GPG key: http://www.strakt.com/~martin/gpg.html
More information about the Python-list
mailing list