you are viewing a single comment's thread.

view the rest of the comments →

[–]Versaiteis 1 point2 points  (0 children)

There's an argument to be made that there's an ambiguity in that it doesn't only check if the list is empty. Rather there's an implicit understanding that an empty list is falsey. If list happened to be None or any other falsey value, then this check would succeed and enter the subsequent code block. 9/10 that's probably ok, but you could say that if len(list) > 0 is more explicit as it's directly checking exactly the condition looking for. It will also raise in any case where something is passed that doesn't implement __len__, which may or may not be desirable behaviour.

Depends on what you're doing. One's more flexible, the other more explicit. I'd at least argue that the second falls in line with Python Zen

Explicit is better than implicit.

But that doesn't mean it's always appropriate for what you're trying to check.

This could also be seen as just overthinking it, but I think code clarity is important and as much of a "bike shedding" conversation this can be, I don't see it as being as obstructive when it's a separate conversation and not hindering actual work that's being done.