I would like to create a list which has values which correspond to another list. For example if I had:
listA = [1, 2, 3, 4, 5,...]
and I would like to create another list which is the same, except all the values were varied according to x^2 (or any other function), giving:
listB = [1, 4, 9, 16,25, ...]
I have already tried to do this by doing a while loop:
listA = [1, 2, 3, 4]
listB = range(1, 4, 1)
i = 0
while i <= 4:
listB [i] = (listA [i]) ** 2
i = i + 1
print listA
print listB
But it just spits out an error message:
Traceback (most recent call last):
File "/home/tim/Desktop/Python/test.py", line 5, in <module>
listB [i] = (listA [i]) ** 2
IndexError: list assignment index out of range