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

holger krekel pyth at devel.trillke.net
Sun Jun 2 05:58:33 EDT 2002


Shagshag13 wrote:
> I had a huge list containing consuming data, as i only need a one pass in a
> for statement,
> i'm wondering if by doing this with a pop i could save memory ? (as i think
> that python
> free it after the pop...)
> 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

try a.pop(0) :-)

    holger





More information about the Python-list mailing list