Alex Rivera | Logout

How do I check if a list is empty?

Asked 2008-09-10T06:20:11.000
3222

For example, if passed the following:

a = []

How do I check to see if a is empty?

Edit
Report

1 Answer

76

len() is an O(1) operation for Python lists, strings, dicts, and sets. Python internally keeps track of the number of elements in these containers.

JavaScript has a similar notion of truthy/falsy.

answered 2008-09-15T05:50:48.547

Your Answer