Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

python-AttributeError: 'NoneType' object has no attribute 'remove'

Asked by Grace Apr 13, 2021 576 views 1 answer
Share

About this question

I have a 3D list in python like:
features= [ [[1,2,3],[1,2,3],[1,2,3]] ,None , [[1,2,3],[1,2,3],[1,2,3]],
        [[1,2,3],[1,2,3],[1,2,3]], None,None,[[1,2,3],[1,2,3],[1,2,3]] ]
I expect to see:
features=[ [[1,2,3],[1,2,3],[1,2,3]] ,[[1,2,3],[1,2,3],[1,2,3]],
               [[1,2,3],[1,2,3],[1,2,3]] ,[[1,2,3],[1,2,3],[1,2,3]] ]
When I try to remove None using the following code:
for i in range(len(features)):
if features[i]==None:
    features[i].remove()
It produces the error :
AttributeError: 'NoneType' object has no attribute 'remove'
If I try this:
for i in range(len(features)):
if features[i]==None:
    del features[i]
It produces the error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Lastly, I tried this code:
for i in range(len(features)):
if features[i]==None:
    features[i]=filter(None,features[i])
It produced the error :-
TypeError: 'NoneType' object is not iterable
How can I fix this error?

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.