Use a list as stack/queue in Python