I have problem with list in python.
here is the simple codes:
x = [scipy.poly1d([ 1., 0., 0.]),2,3,4,5,'foward']
for i in range (len(x)) :
if x [i] == 'foward':
print 'check!'
when it’s run it will say:
return NX.alltrue(self.coeffs == other.coeffs)
AttributeError: ‘str’ object has no attribute ‘coeffs’
but when i change the x into :
x = [1,2,3,4,5,'foward']
the program will run no problem.
is there someone could explain to me why? and what should i do? actually i have a fix list of data (x) which return attribute error like above and i don’t want to change the format of it and what its contain.
or quick-and-dirty:
You should also use the
for .. inloop to iterate over the list:If you need
i, too: