I'm trying to sort through a list of lists. How could I go about printing or iterating over the first and last elements in each list? non-working code below:
from numpy import *
xs=[[1.,2.,3.],[4.,5.,6.],[7.,8.,9.]]
for i in xs:
for j in xs[i]:
print(xs[1],xs[-1])
Traceback error if needed:
runfile('/Users/Alex/untitled9.py', wdir='/Users/Alex')
Traceback (most recent call last):
File "<ipython-input-14-8a28382c7f81>", line 1, in <module>
runfile('/Users/Alex/untitled9.py', wdir='/Users/Alex')
File "/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/Alex/untitled9.py", line 13, in <module>
for j in xs[i]:
TypeError: list indices must be integers or slices, not list