This is easy enough to put in your own toolkit:

>>> is_empty = bool

All done!

On Tue, Aug 24, 2021, 6:04 PM Tim Hoffmann via Python-ideas <
python-ideas@python.org> wrote:

> I also have the feeling that this is going round in circles. So let me get
> back to the core question:
>
> **How do you check if a container is empty?**
>
> IMHO the answer should not depend on the container. While emptiness may
> mean different things for different types. The check syntax can and should
> still be uniform.
>
> Not a solution:
> 0) The current `if not seq` syntax. "check Falsiness instead of emptiness"
> is a simplification, which is not always possible.
>
> Possible solutions:
> 1) Always use `if len(seq) == 0`. I think, this would works. But would we
> want to write that in PEP-8 instead of `if not seq`? To me, this feels a
> bit too low level.
> 2) A protocol would formalize that concept by building respective syntax
> into the language. But I concede that it may be overkill.
> 3) The simple solution would be to add `is_empty()` methods to all stdlib
> containers and encourage third party libs to adopt that convention as well.
> That would give a uniform syntax by convention.
>
> Reflecting the discussion in this thread, I now favor variant 3).
>
> Tim
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/RNI2JYDY44LDV7LAGNAFT7IJD5CJT2GX/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EM3MW27ZLEZYN3RKARZHZKFRWJTZPDU7/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to