Array of 2^n

John Thingstad john.thingstad at chello.no
Sun Oct 21 09:15:56 EDT 2001


> 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?

The fastest, cleanest way would probably be using list comprehentions:

l = [2**i for i in range(10)]






More information about the Python-list mailing list