Lists in Python - AttributeError: 'str' object has no attribute 'coeffs'
arrays, list, python
Solution
if isinstance(x[i], basestring) and x[i] == 'forward'
or quick-and-dirty:
if str(x[i]) == 'forward'
You should also use the `for .. in` loop to iterate over the list:
for elem in x:
if isinstance(elem, basestring) and elem == 'forward':
print 'Check'
If you need `i`, too:
for i, elem in enumerate(x):
Problem
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.