Loop Backwards

Dave davidworley at gmail.com
Wed Mar 15 16:59:41 EST 2006


>> or (more perlish at first sight):

>> for item in alist[::-1]:
>>   do_something_with(item)

>No "or" here. The [::-1] version creates a whole new list in memory,
>it's silly to believe both will behave equally (well, strictly speaking
>they will, but one will use twice more memory than the other).

Thank you for your reply.

Please be mindful of making statements such as:
"it's silly to believe both will behave equally"

One of the greatest weaknesses of Python is the less than friendly
attitude Pythonistas display towards one another. Bruno's suggestions
were valid, given the original question. Even if I had asked for the
most efficient method of iterating through a list in reverse, this
response is unwarranted.

This example is why everyone is more excited about Ruby than Python. If
we become more friendly to each other, Python will win!




More information about the Python-list mailing list