Reverse function python? How to use?

Nick Vatamaniuc vatamane at gmail.com
Sun Oct 29 14:50:30 EST 2006


Use the list's reverse() function. The only thing to keep in mind is
that it will reverse in-place.
Here is an example:
--------------------------------
In [1]: l=[1,2,3]

In [2]: l.reverse()

In [3]: l
Out[3]: [3, 2, 1]
------------------------------------
So you could accumulate your results in a list then apply reverse() on
it.

Hope this helps,
Nick Vatamaniuc


frankie_85 wrote:
> Ok I'm really lost (I'm new to python) how to use the reverse function.
>
>
> I made a little program which basically the a, b, c, d, e which I have
> listed below and basically I want it th result to be printed reverse so
> instead doing "print e, d, c, b, a", I'd like to use the reverse
> function
>
> Can someone give pointersguidelines / on how to do it?
>
> [code]
>     a = str(math.sqrt(math.fabs(x1)) + 5*((math.pow(x1,3))))
>     b = str(math.sqrt(math.fabs(x2)) + 5*((math.pow(x2,3))))
>     c = str(math.sqrt(math.fabs(x3)) + 5*((math.pow(x3,3))))
>     d = str(math.sqrt(math.fabs(x4)) + 5*((math.pow(x4,3))))
>     e = str(math.sqrt(math.fabs(x5)) + 5*((math.pow(x5,3))))
> [/code]
> 
>  Thanks in advance




More information about the Python-list mailing list