Top-rated recipes tagged "slices"http://code.activestate.com/recipes/tags/slices/top/2008-08-18T09:26:07-07:00ActiveState Code RecipesUser List Subclass (Python)
2008-08-18T09:26:07-07:00nosklohttp://code.activestate.com/recipes/users/4166478/http://code.activestate.com/recipes/576428-user-list-subclass/
<p style="color: grey">
Python
recipe 576428
by <a href="/recipes/users/4166478/">nosklo</a>
(<a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/slices/">slices</a>, <a href="/recipes/tags/subclass/">subclass</a>, <a href="/recipes/tags/__getitem__/">__getitem__</a>).
Revision 2.
</p>
<p>As subclassing list has a problem when using __getitem__, __delitem__ and __setitem__ methods with slices (they don't get called because parent implements __getslice__, __delslice__ and __setslice__ respectively), I've coded this UserList class that is a subclass of list, but overwrites these methods.
By subclassing this class, you can overwrite __getitem__ and it will be called correctly for slices.</p>