Velocity Reviews > generating range of numbers

# generating range of numbers

vimal
Guest
Posts: n/a

 10-03-2007
hi all,

i am new to python.....
i just want to generate numbers in the form like:

1,2,4,8,16,32.....to a maximum of 1024

using a range function

Amit Khemka
Guest
Posts: n/a

 10-03-2007
On 10/3/07, vimal <(E-Mail Removed)> wrote:
> hi all,
>
> i am new to python.....
> i just want to generate numbers in the form like:
>
> 1,2,4,8,16,32.....to a maximum of 1024
>
> using a range function

[2**i for i in range(11)]

This is a list comprehension, for more have a look at
http://docs.python.org/tut/node7.htm...00000000000000

Cheers,

--
----
Amit Khemka
website: www.onyomo.com
wap-site: www.owap.in

Michael Bentley
Guest
Posts: n/a

 10-03-2007

On Oct 3, 2007, at 2:18 AM, vimal wrote:

> i am new to python.....
> i just want to generate numbers in the form like:
>
> 1,2,4,8,16,32.....to a maximum of 1024
>
> using a range function

I don't think it can be done with *only* a range function...

import math
[pow(2, x) for x in range(math.log(1024, 2) +1)]

hth,
Michael
---
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it. --Brian W. Kernighan

Wildemar Wildenburger
Guest
Posts: n/a

 10-03-2007
vimal wrote:
> hi all,
>
> i am new to python.....
> i just want to generate numbers in the form like:
>
> 1,2,4,8,16,32.....to a maximum of 1024
>
> using a range function
>

Homework?

/W