Python: pop from empty list

This one..

exporterslist.pop(0) if exporterslist else False

..is somewhat the same as the accepted answer of @nightshadequeen's just shorter:

>>> exporterslist = []   
>>> exporterslist.pop(0) if exporterslist else False   
False

or maybe you could use this to get no return at all:

exporterslist.pop(0) if exporterslist else None

>>> exporterslist = [] 
>>> exporterslist.pop(0) if exporterslist else None
>>> 

You can also use a try/except

try:
    importer = exporterslist.pop(0)
except IndexError as e:
    print(e)

If you are always popping from the front you may find a deque a better option as deque.popleft() is 0(1).


You're on the right track.

if exporterslist: #if empty_list will evaluate as false.
    importer = exporterslist.pop(0)
else:
    #Get next entry? Do something else?