60
you are viewing a single comment's thread
view the rest of the comments
[-] Michal@programming.dev 6 points 4 days ago* (last edited 4 days ago)

Makes perfect sense. If you're checking if a collection is empty you don't need to know its exact size. Getting the size can be very inefficient in collections like linked lists or trees, if you have to follow all nodes. To check if it's empty, all you need fo know if at least one item exists. If one does, there's no point counting the rest.

People who don't understand the difference will probably not understand the difference between passing a list and passing an literator/generator to any() .

this post was submitted on 24 Apr 2025
60 points (94.1% liked)

Python

7049 readers
50 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 2 years ago
MODERATORS