[Tutor] Make a linked list subscriptable?

Mats Wichmann mats at wichmann.us
Thu Jul 11 10:55:01 EDT 2019


On 7/10/19 6:30 PM, Sarah Hembree wrote:
> How might I best make a linked list subscriptable? Below is skeleton code
> for a linked list (my
> actual is much more). I've done __iter__ and __next__ but I would like to
> be able to do start:stop:stride I just can't figure out how. Suggestions or
> just hints please?

As a learning exercise this can be interesting, but as to practical
applications, one would like to ask "why"?  If index into the list is
important, then choose a regular list; the "interesting" part of a
linked list, which is "next node" is then available as index + 1.


More information about the Tutor mailing list