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

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Varun Kacholia Java 11 08-03-2006 01:32 PM Wally ASP .Net 1 03-20-2006 12:19 AM laura.paterson@gmail.com Java 3 02-09-2006 09:04 AM Stephen Briley Python 3 02-16-2004 02:01 AM lallous C++ 5 10-20-2003 12:17 PM