[Tutor] Inverse range

Bastien Verbinnen bastien.verbinnen at pandora.be
Wed Sep 6 14:09:57 CEST 2006


You could do the folowing with range:

for f in range(4,0,-1)
    print f

This should give you the wanted result. You start from 4 and range to 0 (not
included), by sustracting 1 each time.

Cheers,
Bas.

----- Original Message ----- 
From: "Morten Juhl Johansen" <info at pythonin.dk>
To: <tutor at python.org>
Sent: Wednesday, September 06, 2006 1:15 PM
Subject: [Tutor] Inverse range


> # Newbie warning
>
> I am playing with Python. Playing as in learning.
> Is it possible to reverse a range sequence? If, for instance, I call:
>
> for f in range( 1,5 ):
> print f
>
> - I get:
> 1
> 2
> 3
> 4
>
> Is it possible to reverse it? As in:
> 4
> 3
> 2
> 1
>
> Yours,
> Morten
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>



More information about the Tutor mailing list