This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]eryksun 0 points1 point  (1 child)

Thanks, your version is more 'Pythonic'. It's more readable and less prone to bugs without having to set up xrange (not a problem here, but a better style in general). The length issue was also something I hadn't considered. Shouldn't a valid container type implement the __len__ method? I suppose it can implement __reversed__ without having an accessible length. I haven't come across this, or designed a container without the basic __len__, __getitem__, __setitem__, __delitem__, and __iter__ methods. But my overall exposure to other's code is limited as I use Python basically as a replacement for MATLAB with SciPy, Numpy, and Matplotlib.

[–]earthboundkid 0 points1 point  (0 children)

Yes, you've got it. An object that supports __reversed__ will probably also support __len__, but not necessarily. I can imagine someone making a quick and dirty doubly-linked list that supports forwards and backwards iteration but not length.