Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (47.6k points)

I am getting an error from this Python code:

with open('names') as f: 

names = 

names = names.split('\n') 

names.pop(len(names) - 1) 

names = shuffle(names) 


assert len(names) > 100


Python: TypeError: object of type 'NoneType' has no len()

The assert statement is throwing this error, what am I doing wrong?

1 Answer

0 votes
by (106k points)

To get rid of this error you can use shuffle(names) is an in-place operation. Drop the assignment.

This function returns None and that's why you have the error:

TypeError: object of type 'NoneType' has no len()

Browse Categories