60
Python Performance: Why 'if not list' is 2x Faster Than Using len()
(blog.codingconfessions.com)
Welcome to the Python community on the programming.dev Lemmy instance!
Past
November 2023
October 2023
July 2023
August 2023
September 2023
Same with dictionaries, iterators (will consume the iterator!), and anything else that has a length.
I've actually had the string instead of list issue a number of times, because sometimes things get off and it's hard to track down where things went wrong.
For this reason, I think type hints are the way to go. Use them consistently w/ a static analysis tool like
pyright
and you'll catch a lot of these issues before running into cryptic error messages.