Array of 2^n

Artie Gold agold at bga.com
Sat Oct 20 23:17:25 EDT 2001


Moshe wrote:
> 
> Okay, python newbie here. I'm liking what I see, but it seems like there
> are holes in the features of python's objects. I remember programming in
> squeak (an extension of smalltalk), and you could do complex operations on
> lists, and it would apply the result to each item. I want to make a n-item
> list such that mylist[i] = 2**i. How can I generate such a list in Python?
> 
As an example, suppose you wanted the first 10 powers of 2 (i.e. 2**0 to
2**9)

map(lambda x: 2**x, range(0,10)) 

would do it. Ayn b'ah'yah.

HTH,
--ag
-- 
Artie Gold, Austin, TX  (finger the cs.utexas.edu account for more info)
mailto:agold at bga.com or mailto:agold at cs.utexas.edu
--
"Verbing weirds language." -- Calvin



More information about the Python-list mailing list