Reversing an iterator with older version of Python
A.M. Kuchling
amk at amk.ca
Wed Nov 12 15:11:29 EST 2003
On 12 Nov 2003 10:22:12 -0800,
Aki Niimura <akineko at pacbell.net> wrote:
> I need to reverse an iterator in my program.
Convert it to a list and then reverse the list:
L = list(iterator)
L.reverse()
This means that the contents must fit in memory, but that's probably OK; if
you want to read the lines of a 2-gigabyte file in reverse order, you're
better off writing some custom code for reading the file.
--amk
More information about the Python-list
mailing list