linked structures of data do not have to be shifted as is required by the python list this is especially true when prepending items on the other handthe python list is better choice in those applications where individual elements must be accessed by index this can be simulated with linked listbut it requires traversal of the listresulting in linear operation whereas the python list only requires constant time linked list iterators suppose we want to provide an iterator for our bag adt implemented using linked list as we did for the one implemented using python list the process would be similarbut our iterator class would have to keep track of the current node in the linked list instead of the current element in the python list we define bag iterator class in listing which would be placed within the llistbag py module that can be used to iterate over the linked list listing an iterator for the bag class implemented using linked list defines linked list iterator for the bag adt class _bagiterator def __init__selflisthead )self _curnode listhead def __iter__self )return self def nextself )if self _curnode is none raise stopiteration else item self _curnode item self _curnode self _curnode next return item when iterating over linked listwe need only keep track of the current node being processed and thus we use single data field curnode in the iterator this reference will be advanced through the linked list as the for loop iterates over the nodes as was done with our python list-based bag classthe linked list version must include the iter method (shown in lines - of listing )which returns an instance of the bagiterator class figure illustrates the bag and bagiterator objects at the beginning of the for loop the curnode pointer in the bagiterator object is used just like the curnode pointer we used when directly performing linked list traversal earlier in the the only difference is that we don' include while loop since python manages the iteration for us as part of the for loop notethe iterator objects can be used with any singly linked list configuration to traverse the nodes and return the data contained in each