checking if a list is empty

Chris Angelico rosuav at gmail.com
Thu May 12 10:13:06 EDT 2011


On Fri, May 13, 2011 at 12:02 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> Chris Angelico wrote:
>>
>> On Thu, May 12, 2011 at 7:02 AM, Ian <hobson42 at gmail.com> wrote:
>>>
>>> In the "real world"  lists of zero items do not exist.
>>> You don't go shopping with a shopping list of zero items.
>>
>> Actually, yes you do. You maintain your shopping list between trips;
>> whenever you need something, you put it on the list immediately. Then
>> when you go shopping, you just take the list with you (if you're
>> lucky, you don't need to move or copy it at all, you just get another
>> reference to it). Once you're done, you empty the list - you now have
>> a shopping list with zero items (until you get home and realize you
>> forgot something).
>
> Um -- you contradicted Ian, then contradicted yourself -- according to your
> scenario your shopping list is *not* empty when you go to the store
> (otherwise known as "going shopping" ;).

Ehh, mea culpa (I shouldn't post in haste). Replace "Actually, yes you
do" with "Actually, yes they do". Indeed you do not *go shopping* with
a list of zero items; but a shopping list with no items on it DOES
exist (when you come back).

def do_shopping():
  if shopping_list:
    goto shop; # Muahahahahaha.
    for item in shopping_list:
      inventory.append(item)
    return; # Muahahahaha again!

Chris Angelico



More information about the Python-list mailing list