Intellipaat Back

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

I am getting an error from this Python code:

with open('names') as f: 

names = f.read() 

names = names.split('\n') 

names.pop(len(names) - 1) 

names = shuffle(names) 

f.close() 

assert len(names) > 100

Error:

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()

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...