On May 6, 2:36 am, Jabba Laci <jabba.l...@gmail.com> wrote: > Hi, > > If I want to check if a list is empty, which is the more pythonic way? > > li = [] > > (1) if len(li) == 0: > ... > or > (2) if not li: > ... > > Thanks, > > Laszlo
is there any problem with (3) if li == []: ? Seems to work when I test it and seems to clearly test what you are trying to test. The only problem might be if in some contexts == has the semantics of checking for object identity. -- http://mail.python.org/mailman/listinfo/python-list