simple problem with lists I am just forgetting

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jul 31 15:59:02 EDT 2008


Alexnb:
> How can I test if the list item is empty without getting that exception?

In Python such list cell isn't empty, it's absent. So you can use
len(somelist) to see how much long the list is before accessing its
items. Often you can iterate on the list with a for, so you don't need
to care of the len().

Bye,
bearophile



More information about the Python-list mailing list