IndexError: list assignment index out of range in python 2.7.11
Question: I was just solving a problem using python, and my codes are:

    
    
    from math import sin,pi
    import numpy
    import numpy as np
    import pylab
    N=20
    x = np.linspace(0,1, N)
    def v(x):
        return 100*sin(pi*x)
    
    #set up initial condition
    u0 = [0.0]              # Boundary conditions at t= 0
    for i in range(1,N):
        u0[i] = v(x[i])
    

And I would want to plot the results by updating v(x) in `range(0, N)` after.
it looks simple but perhaps you guys could help since it gives me an error,
like

    
    
    Traceback (most recent call last):
      File "/home/universe/Desktop/Python/sample.py", line 13, in <module>
        u0[i] = v(x[i])
    IndexError: list assignment index out of range
    


Answer: You could change `u0[i] = v(x[i])` to `u0.append(v(x[i]))`. But you should
write more elegantly as

    
    
    u0 = [v(xi) for xi in x]
    

Indices `i` are bug magnets.

