Hi Tim,

I'm sorry if this has been brought up before, but *aside from PEP 8* is
there anything wrong with using "if len(a)" for nonempty, or "if not
len(a)" for empty?

It would seem to work for numpy and pandas arrays, and it works for builtin
sequences. Also, it has the advantage of being 100% backwards compatible.
:-)

Surely conforming to PEP 8 shouldn't need an addition to the language or
stdlib? Or does it not work?

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

> Ethan Furman wrote:
> > On 8/24/21 3:03 PM, Tim Hoffmann via Python-ideas wrote:
> > > **How do you check if a container is empty?**
> > > IMHO the answer should not depend on the container.
> > I think this is the fly in the ointment -- just about everything, from
> len() to bool(), to add, to iter() /all/ depend
> > on the container -- even equality depends on the container.  `and`,
> `or`, and `not` partially depend on the container
> > (via bool()).  Only `is` is truly independent.
>
> Sorry, I think you got me wrong: The meaning and thus implementation
> depends on the type (e.g. each container defines its own __len__()).
> However the syntax for querying length that is still uniformly
> `len(container)`. Likewise I'd like to have a uniform syntax for emptiness,
> and not different syntax for different types (`if not container` / `if
> len(array) == 0` / `if dataframe.empty`).
> _______________________________________________
> 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/LRK6HHQKBH2Y4USB7DAJNOUF5NE62ZYD/
> Code of Conduct: http://python.org/psf/codeofconduct/
>


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
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/5KTHNWMKZBRDQSRO7C4WCX4KG22QWCG2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to