You need to compare against false with type checking as the list may be empty.

Also consider returning early and deindenting the rest of the function.