I am new here and I am in general a beginner in programming and Python. I hope my questions will not become too trivial.

So, the exercise is:

You are supposed to learn to transverse (look at all the elements) in a simple list. In the given framework the code for creating a chained list is written The important thing to remember in this exercise is how to link elements together. This is very common in object-oriented programming. The trick when making a chained list, is to connect several objects of the same class, so that every object has a reference (link) to another object (the next object'). If you so, at any place, save a referance to the first object in the chain (the next object that has not been linked to any other objects), you have a starting point to transverse the whole list of objectsr.

Input consists of whole numbers separated by a break line. Your program is supposed to put these in a chained list, transverse the chained list, and print the highest number.

first = Nonelast = Nonefor line in stdin: previous_last = last last = cube(int(line)) if first == None: first = last else: previous_last.next = last

# Calling the solution function and printing the resultprint trace(first)

We don't have to use the framework to find the solution.

Ok, first of all, I don't really understand the framework. I think I understand the the class "Cube" is creating a cube and initializing the values of weight and next. What I don't understand is how the chained list is getting created. Especially after the part previous_last = last.

I was wondering if perhaps someone could give me a few hints as to how to understand the framework? I would also appreciate, in case nobody wants to baby me through too many steps, if someone could recommend to me what to learn in order to understand this. For example, I figured that I should learn about object oriented programming in Python, so I checked out a few tutorials on YouTube, It made me understand what classes and objects are, but I still have a hard time understanding the framework even after knowing that.

for line in stdin: previous_last = last # create a cube (calls the cube class' __init__() with the number for the vekt argument) last = cube(int(line))

# if there are no cubes yet, make this the first one (as well as last) if first == None: first = last

# if there are already cubes, place this one after the one that was last else: previous_last.next = last

So for going through all of the objects, you're obviously going to start from first.The one after that will be first.next.After that comes the new one's next.When you get to an object who's next is None, you stop.

stranac wrote:I'm not sure how I feel about making students implement linked lists in python...

Academia

Yeah. They love to take python because it is so "easy," and then teach about data structures and sorting algorithms that are completely irrelevant to it.

If you want to teach about ADT in a statically typed non-garbage-collected language, then use a statically typed non-garbage-collected language. I've also recently seen a thread where the student was asked to make all his class attributes private with "properly coded setters and getters"... in python. :headdesk: