Immutable list reverse function

M.-A. Lemburg mal at lemburg.com
Fri Jul 20 15:49:12 EDT 2001


"Martin Sjögren" wrote:
> 
> 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

Take a look at mxTools which you can download from the Python link
below (it's part of the eGenix mx BASE package).

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/




More information about the Python-list mailing list