Pop a list from beginning ? and memory saving...

Benjamin Tai bt98 at doc.ic.ac.uk
Sun Jun 2 05:55:21 EDT 2002


Shagshag13 wrote:

> and is there a way to pop from the beginning  of the list ? (i think i could
> use reverse but
> i don't know if this memory consuming)
>
> >>> a = [1,2,3,4,5,6,7]
> >>> while 1:
>  try:
>   f = a.pop()
>  except IndexError:
>   break
>  print f
>
> thanks,
>
> s13.

You could try a.pop(0), which pop the first instance of the list, like a FIFO.

Thanks

Ben




More information about the Python-list mailing list