A question about "empty" lists in Python

Posted by bitrex on Stack Overflow See other posts from Stack Overflow or by bitrex
Published on 2010-03-11T04:05:42Z Indexed on 2010/03/11 4:39 UTC
Read the original article Hit count: 500

Filed under:

I've started teaching myself Python, and as an exercise I've set myself the task of generating lookup tables I need for another project. I need to generate a list of 256 elements in which each element is the value of math.sin(2pi/256). The problem is I don't know how to generate a list initialized to "dummy" values that I can then use a for loop to step through and assign the values of the sin function. Using list[] seems to create an "empty" list, but with no elements so I get a "list assignment index out of range" error in the loop. Is there a way to this other than explicitly creating a list declaration containing 256 elements all with "0" as a value? Thanks!

© Stack Overflow or respective owner

Related posts about python