The problem
The starter code defines a Node class. Write make_train(values): make one node for each value, in the same order, and link each node to the next through its next attribute. The last node’s next stays None. Return the first node (the head), or None if values is empty.
head = make_train([3, 8, 5])
head.value # 3
head.next.value # 8
head.next.next.value # 5
head.next.next.next # None
The tests walk along your nodes from the head, following next, and compare the values they find. Keep the class name and the attribute names value and next.
Limits
- Up to 100,000 values.
- Do not change the list
values.
Builds on PYTH-5 Classes for nodes.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | Three coaches | Not run | |
| 2 | Returns the first node | Not run | |
| 3 | One coach | Not run | |
| 4 | No coaches | Not run | |
| 5 | Each node is a new object | Not run | |
| 6 | The input is not changed | Not run | |
| 7 | 100,000 coaches | Not run |